You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Item 1: Understand the Relationship Between TypeScript and JavaScript
Things to Remember
TypeScript is a superset of JavaScript: all JavaScript programs are syntactically valid TypeScript programs, but not all TypeScript programs are valid JavaScript programs.
TypeScript adds a static type system that models JavaScript's runtime behavior and tries to spot code that will throw exceptions at runtime.
It is possible for code to pass the type checker but still throw at runtime.
TypeScript disallows some legal but questionable JavaScript constructs such as calling functions with the wrong number of arguments.
Type annotations tell TypeScript your intent and help it distinguish correct and incorrect code.
letcity='new york city';console.log(city.toUppercase());// ~~~~~~~~~~~ Property 'toUppercase' does not exist on type// 'string'. Did you mean 'toUpperCase'?
for(conststateofstates){console.log(state.capitol);// ~~~~~~~ Property 'capitol' does not exist on type// '{ name: string; capital: string; }'.// Did you mean 'capital'?}
conststates=[{name: 'Alabama',capitol: 'Montgomery'},{name: 'Alaska',capitol: 'Juneau'},{name: 'Arizona',capitol: 'Phoenix'},// ...];for(conststateofstates){console.log(state.capital);// ~~~~~~~ Property 'capital' does not exist on type// '{ name: string; capitol: string; }'.// Did you mean 'capitol'?}
interfaceState{name: string;capital: string;}conststates: State[]=[{name: 'Alabama',capitol: 'Montgomery'},// ~~~~~~~{name: 'Alaska',capitol: 'Juneau'},// ~~~~~~~{name: 'Arizona',capitol: 'Phoenix'},// ~~~~~~~ Object literal may only specify known properties,// but 'capitol' does not exist in type 'State'.// Did you mean to write 'capital'?// ...];for(conststateofstates){console.log(state.capital);}
conststates: State[]=[{name: 'Alabama',capital: 'Montgomery'},{name: 'Alaska',capitol: 'Juneau'},// ~~~~~~~ Did you mean to write 'capital'?{name: 'Arizona',capital: 'Phoenix'},// ...];
consta=null+7;// Evaluates to 7 in JS// ~~~~ The value 'null' cannot be used here.constb=[]+12;// Evaluates to '12' in JS// ~~~~~~~ Operator '+' cannot be applied to types ...alert('Hello','TypeScript');// alerts "Hello"// ~~~~~~~~~~~~ Expected 0-1 arguments, but got 2