Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript vs ES6 declaring variable types

In TypeScript I am used to declaring variable types using a syntax such as follows

function f(input: MyClassType)

However I have not seen such a syntax in ES6 or am I missing something here. The same I would declare in ES6

function f(input)

My main point here is that the parameter type declaration is missing.

like image 302
tmp dev Avatar asked Mar 10 '23 00:03

tmp dev


1 Answers

However I have not seen such a syntax in ES6 or am I missing something here.

You are not missing something.

ES6 !== TypeScript

TypeScript is not the same thing as ES6 at all. ES6 is not a typed language. You don't declare a variable or a parameter with a type in Javascript. So, if you somehow had a thought that ES6 was supposed to implement all the syntax used in TypeScript, that's incorrect.

ES6 did implement the class syntax which is pretty similar to what TypeScript was using (but without the types). But, that's just a similarity. ES6 is not a typed language and does not have variables with type declarations.

like image 118
jfriend00 Avatar answered Mar 20 '23 00:03

jfriend00