Skip to content

Instantly share code, notes, and snippets.

@aiya000
Created December 1, 2020 07:11
Show Gist options
  • Select an option

  • Save aiya000/076cec5d3280c17b379a5c80f524d295 to your computer and use it in GitHub Desktop.

Select an option

Save aiya000/076cec5d3280c17b379a5c80f524d295 to your computer and use it in GitHub Desktop.
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