0
  • 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 2

5
+25

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.

Sign up to request clarification or add additional context in comments.

3 Comments

hey do you know why I do not see the delete button when I click three dots...is it a css issue I am speaking with respect to this div <div class="pai-del-menu">Delete</div>
@texirv Its z-index is not big enough.
@texirv The problem with your code should be clear by now. Asking anything more is just using StackOverflow as a code writing service.
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.

2 Comments

Hey can you update my code like what changes I need to make??
@texirv not really, I don't know what pai_to_delete is supposed to be, or why you're trying to use Rx in the broken TypeScript but don't use it in the original. You haven't really provided enough information about what you're trying to do, which is why you have downvotes and a vote to close. Finally, you need typings imported for the libraries that you rely on, which means the fix for this is a whole project, rather than a single script fix. You may be better off putting this project on GitHub rather than trying to use code snippets and JSFiddle.