Closed
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.