-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overloads returning type predicate types are always incompatible with implementation #4180
Comments
Specific use case found with @roganov here. namespace ActionType {
export type Foo = string & { _fooTag: any };
export const Foo = <Foo>"Foo";
export type Bar = string & { _barTag: any };
export const Bar = <Bar>"Bar";
}
type ActionType = ActionType.Foo |
ActionType.Bar;
interface BaseAction {
type: ActionType;
}
interface FooAction extends BaseAction {
type: ActionType.Foo;
foo: number;
}
interface BarAction extends BaseAction {
type: ActionType.Bar;
bar: string;
}
function isActionType(action: BaseAction, type: ActionType.Foo): action is FooAction;
function isActionType(action: BaseAction, type: ActionType.Bar): action is BarAction;
function isActionType(action: BaseAction, type: ActionType): boolean {
return action.type === type;
}
let handleAction = (action: BaseAction) => {
if (isActionType(action, ActionType.Foo)) {
let foo = action.foo; // OK
let bar = action.bar; // type error
}
else if (isActionType(action, ActionType.Bar)) {
let bar = action.bar; // OK
}
} |
See #3262 (comment). |
Gotcha - but there was no formal issue filed for that, correct? |
Correct, at least non that I knew of. |
@JsonFreeman in the comment that @tinganho linked to, you mentioned that this is a problem that "we've known about". What problem were you referring to specifically? |
I was referring to #943. |
Right, I was sure we had an issue referring to that. Glad I'm not going nuts 😄. @mhegazy. |
This should be fixed for TypeScript 1.8. |
Version 1.6.0-dev.20150805
Currently yields
I think this should be fixed in time for 1.6; being able to do this would enable some useful patterns.
The text was updated successfully, but these errors were encountered: