-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Closed
Copy link
Labels
Help WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
Description
π Search Terms
covariant covariance contravariant contravariance inference candidates subtyping assignable subtype
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
type Request<TSchema extends Schema> = {
query: TSchema["query"];
};
type Schema = { query?: unknown; body?: unknown };
declare function route<TSchema extends Schema>(obj: {
pre: (a: TSchema) => void;
schema: TSchema;
handle: (req: Request<TSchema>) => void;
}): void;
const validate = (_: { query?: unknown; body?: unknown }) => {};
route({
pre: validate,
schema: {
query: "",
},
handle: (req) => {
const test: string = req.query;
},
});
export {};
π Actual behavior
assignment to test
fails because { query?: unknown; body?: unknown; }
was inferred there
π Expected behavior
I'd expect { query: string }
to be inferred here and the assignment to test
to succeed
Additional information about the issue
This is a reduced version of this failure.
Metadata
Metadata
Assignees
Labels
Help WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases