Created
July 11, 2020 19:46
-
-
Save amitzur/f68951ab6d1fb77b4735911303c880d4 to your computer and use it in GitHub Desktop.
Example for issue with typescript
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
import {Thing, ThingType, Other} from './things' | |
function foo() : typeof ThingType { | |
const thing = new Thing('bla', new Other()) | |
return thing | |
} |
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
export class Thing_1<T> { | |
prop:T; | |
constructor(x : T) { | |
this.prop = x | |
} | |
} | |
export class Thing_2<T> { | |
prop:T; | |
constructor(x : T) { | |
this.prop = x | |
} | |
} | |
export class Other {} | |
export class Thing<T> { | |
constructor(value: T, typeArg) { | |
if (typeArg instanceof Other) { | |
return new Thing_1(value) | |
} else { | |
return new Thing_2(value) | |
} | |
} | |
} | |
export var ThingType: new <T>(value: any, typeArg: T) => T extends Other ? Thing_1<T> : Thing_2<T>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment