-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
TypeScript Version: 3.4 and up
Search Terms:
unknown, 3.4, type inference fails, method overload
Code
type Circle = {
type: "CIRCLE";
radius: number;
};
type Square = {
type: "SQUARE";
sideLength: number;
};
type Shape = Circle | Square;
class Evt<T> {
public attach<U>(
matcher: (data: T)=> [U] | undefined,
callback: (transformedData: U)=> void
): Promise<U>;
public attach(
matcher: (data: T) => boolean,
callback: (data: T) => void
): Promise<T>;
public attach(...args: any[]){
return null as any;
}
}
const evtShape = new Evt<Shape>();
//OK
const prRadius = evtShape.attach(
shape => shape.type === "CIRCLE" ? [shape.radius] : undefined,
radius => { }
);
const prShape = evtShape.attach(
shape => true,
shape => { } //<====== In typescript 3.4 and up shape is unknown
);
Expected behavior:
In the last line, shape should be of type Shape. In typescript 3.4 and up it is of type unknown.
Actual behavior:
mscottnelson
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code