Skip to content

Instantly share code, notes, and snippets.

@augustl
Created November 27, 2018 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save augustl/541945400685c913900e0f5a66e058d1 to your computer and use it in GitHub Desktop.
Save augustl/541945400685c913900e0f5a66e058d1 to your computer and use it in GitHub Desktop.
$> tsc src/foo.ts
src/foo.ts:29:20 - error TS2339: Property 'length' does not exist on type 'string | {}'.
Property 'length' does not exist on type '{}'.
18 new Foo("wot").x().length
~~~~~~
class Foo<V> {
value: V
constructor(val: V) {
this.value = val
}
x<T>(x?: T): V | T {
if (x === null || x === undefined) {
return this.value
} else {
return x
}
}
}
new Foo("wot").x().length
new Foo("wot").x<any>().length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment