Created
January 17, 2022 06:10
-
-
Save vinhlee95/8881d780bdde3ceaf6d58014986fa790 to your computer and use it in GitHub Desktop.
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
// Anything is assignable to unknown | |
const foo: unknown = 1 // <- we can assign a number to a unknown var | |
const bar: unknown = true // <- same with other primitive types such as boolean | |
// But unknown isn’t assignable to anything but itself | |
const myString: string = foo // <- ⛔️⛔️⛔️ unknown type is not assignable to string type | |
const isGreaterThan10 = (val: unknown) => val > 10 // <- ⛔️⛔️⛔️ because val has unknown type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment