Last active
September 6, 2020 09:09
-
-
Save alenvlahovljak/db8cb937f2b9491125a737503c5e211b to your computer and use it in GitHub Desktop.
How to adopt a static typing?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//* Type Inference *// | |
// The system can guess that array will contain only numbers | |
// based on the array's initialization. | |
const arr1 = [14, 21, 28]; | |
arr1.push(15); | |
arr1.push("Hello World!"); | |
// Type Inference is going to set the type to 'any' | |
// because we initialize an empty array | |
const arr2 = []; | |
arr2.push(27); | |
arr2.push("Hi there!"); | |
// Type Annotation is a must in this case | |
let arr3: number[]; | |
arr3.push(77); | |
arr3.push("It's a string!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment