0

I just started learning TypeScript and I don't have any prior knowledge of JavaScript. I know both are kind of similar. I am facing an issue at runtime, not compile time. Perhaps I am misusing the syntax? The video tutorial I am currently learning from is pretty old. Maybe th syntax has changed in the meantime. Can you please tell me, what the problem is with the code? I would be thankful for typescript best practices and guides.

Code:

class Point{
    
   x: number;
   y: number;
    
    draw(){
        console.log('X ' + this.x + ',Y ' + this.y);
    }

    GetDistance(another: Point){
        //....
    }

}

let p = new Point();
p.draw();

Console output:

Error: x: number;

SyntaxError: Unexpected identifier
[90m    at wrapSafe (internal/modules/cjs/loader.js:1054:16)[39m
[90m    at Module._compile (internal/modules/cjs/loader.js:1102:27)[39m
[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)[39m
[90m    at Module.load (internal/modules/cjs/loader.js:986:32)[39m
[90m    at Function.Module._load (internal/modules/cjs/loader.js:879:14)[39m
[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)[39m
[90m    at internal/main/run_main_module.js:17:47[39m
5
  • 1
    you should post the complete code and error here, for future ref. just in case the image on the image hosting platform is removed Commented Jul 19, 2020 at 8:03
  • Also if you think the syntax has changed, why aren't you looking at the official docs? Commented Jul 19, 2020 at 8:05
  • ok...thank you very much for the advise...well actually i found out the solution for above problem...so how can i close this post Commented Jul 19, 2020 at 8:09
  • or should i remove the post?? Commented Jul 19, 2020 at 8:10
  • i'd recommend editing your post to include the code and the error, then posting the solution as the answer so that it can be helpful to others Commented Jul 19, 2020 at 8:12

1 Answer 1

1

So i was able to solve above problem. Actually i was trying to load TypeSciprt file that is .ts file rather than .js file. I got to know When we write TypeScript files we can compile them with the compiler (tsc) and it outputs .js file which we can load in the browser nodejs

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.