Skip to content

Instantly share code, notes, and snippets.

@amitzur
Created July 11, 2020 19:46
Show Gist options
  • Save amitzur/f68951ab6d1fb77b4735911303c880d4 to your computer and use it in GitHub Desktop.
Save amitzur/f68951ab6d1fb77b4735911303c880d4 to your computer and use it in GitHub Desktop.
Example for issue with typescript
import {Thing, ThingType, Other} from './things'
function foo() : typeof ThingType {
const thing = new Thing('bla', new Other())
return thing
}
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