Typescript variables: Difference between revisions

From wikinotes
Line 2: Line 2:
<blockquote>
<blockquote>
<syntaxhighlight lang="typescript">
<syntaxhighlight lang="typescript">
let name: string = "alex"; // type annotation
let name: string = "alex";   // type annotation
let name = "alex";         // inferred type 'string'  
let name = "alex";           // inferred type 'string'
let foo = bar.baz() as User; // type assertion (I know this is a user, but compiler won't)
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Assignment -->
</blockquote><!-- Assignment -->

Revision as of 03:34, 11 December 2022

Assignment

let name: string = "alex";   // type annotation
let name = "alex";           // inferred type 'string'
let foo = bar.baz() as User; // type assertion (I know this is a user, but compiler won't)

Scope