Created
February 23, 2023 14:57
-
-
Save ransomw/95d9b16e1ad964a878830825bb7a24a1 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
// the `unknown` type is similar to `any`, except it is less permissive on the RHS of assignment | |
let unknownType: unknown = 'asdf' | |
let anyType: any = 'asdf'; | |
let someString: string; | |
// now, | |
someString = anyType; | |
// is permitted, while | |
// someString = unknownType | |
// errors | |
// by the way, note that it's possible to have the dynamic and static types | |
// _of the same variable_ differ because of the permissiveness of the 'any' | |
// type on the RHS of assignment. | |
anyType = 1 | |
someString = anyType; | |
console.log(typeof someString); // 'number' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment