- I am trying to learn typescript.
- I have an ui working in jquery.
- I am trying to move it in typescript.
- but I am not successful. I am trying to move everything inside this method WholeUI()
- I am getting error.
- cann you tell me how to fix it.
working fiddle. http://jsfiddle.net/46aqscwv/
breaking fiddle http://jsfiddle.net/Ls1aqLv1/
error
Uncaught SyntaxError: Unexpected token ( at new Function (<anonymous>) at exec (typescript.js:41) at HTMLDocument.runScripts (typescript.js:41)
code
function WholeUI() { $(document).ready(function() { $('ul.tabs li').click(function() { var tab_id = $(this).attr('data-tab'); $('ul.tabs li').removeClass('current'); $('.tab-content').removeClass('current'); $(this).addClass('current'); $("#" + tab_id).addClass('current'); })
2 Answers
Answers 1
Seems like for some reason JSFiddle can't transpile your Typescript code into a working Javascript code. In particular this part of your code (in typescript):
users.map(u => ({ FileName: u.login }))
is transpiled into this (javascript with wrong syntax):
users.map(function (u) ({ FileName: u.login }))
Modifying the arrow function gets rid of the error (typescript and javascript):
users.map(function (u) { return ({ FileName: u.login }) })
Another problem is you are not calling the WholeUI
function. You can see a working example here.
Answers 2
Fiddle's aren't terribly good for editing TypeScript code, as they don't give particularly useful errors when the syntax is invalid.
Instead try using an editor like VS Code - opening this as a .ts
file in any such editor finds numerous errors, including undeclared variables (pai_to_delete
) and missing type definitions for jQuery, kendoWindow and Rx.
0 comments:
Post a Comment