Created
November 27, 2018 16:37
-
-
Save augustl/541945400685c913900e0f5a66e058d1 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
$> 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 | |
~~~~~~ | |
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
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