Created
December 1, 2020 07:11
-
-
Save aiya000/076cec5d3280c17b379a5c80f524d295 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| interface Foo { | |
| x: number | string | |
| } | |
| interface Bar { | |
| x: number | |
| } | |
| function main(): void { | |
| const foo: Foo = {x: 10} | |
| if (typeof foo.x === 'string') { | |
| return | |
| } | |
| // Compile Error! | |
| // | |
| // Type 'Foo' is not assignable to type 'Bar'. | |
| // Types of property 'x' are incompatible. | |
| // Type 'string | number' is not assignable to type 'number'. | |
| // Type 'string' is not assignable to type 'number'. | |
| const bar: Bar = foo | |
| console.log(foo, bar) | |
| } | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment