### π Search Terms `satisfies upcast`, `satisfies changes typechecking behavior` ### π Version & Regression Information - This is the behavior in every version I tried, and I reviewed the FAQ for entries about `satisfies` ### β― Playground Link [Playground link](https://www.typescriptlang.org/play/?ts=5.7.2#code/C4TwDgpgBAKghgIwDbQLxQETIPYGMDWGUAPprtkirsAJbYB2RpGAzmHLhBgFDeiRQAShHIAnACYAFbDXrAIogDwwoEAB7z64lrEQoAfFHQBvbgEgA2jAD6UWbAC6ALiimzZmuJctgo2QHMAGnMzYD0IFxtzAF9uaKsHXgAzAFd6ajp6KH9lVQ0ILR14ZAh9AApgSIBKF2ExKRk5BWVwwzcAenaoAFV07ABbfoLaen8oAAMWOFoWJJoIHTrsCWlZeSVig3GoOCSkkWAdAHcACwhgM9EoC5odMFFsf1E4fuvwETOCFgA6c3J6HxQNRGVzXcIuYCBOxeTBJbDYIjRHY6f6AzpQKYzOYLIQiZYNNbNTalcyic4pURZNRxIA) ### π» Code ```ts type Table = "block" | "collection" | "space" type RecordPointer<T extends Table> = { [T_ in T]: { id: string, table: T_ } }[T] function g<T extends Table>(t: T): RecordPointer<Table> { // Uncommenting `satisfies RecordPointer<Table>` affects whether this program typechecks. const x = { table: t, id: "foo" } as const // satisfies RecordPointer<Table> return x } ``` ### π Actual behavior This program fails to typecheck as written: ```ts Type '{ readonly table: T; readonly id: "foo"; }' is not assignable to type 'RecordPointer<Table>'. Type '{ readonly table: T; readonly id: "foo"; }' is not assignable to type '{ id: string; table: "space"; }'. Types of property 'table' are incompatible. Type 'T' is not assignable to type '"space"'. Type 'Table' is not assignable to type '"space"'. Type '"block"' is not assignable to type '"space"'.(2322) ``` However, if we uncomment the `satisfies` expression on the second-to-last line, the type error goes away: ```diff function g<T extends Table>(t: T): RecordPointer<Table> { - const x = { table: t, id: "foo" } as const + const x = { table: t, id: "foo" } as const satisfies RecordPointer<Table> return x } ``` ### π Expected behavior My understanding from reading #47920 is that: - `satisfies` does not perform safe upcast - `e satisfies T` should have the inferred type `typeof e`, rather than `T` or `T & typeof e` Assuming both of these are correct, I would not expect `satisfies` to affect whether this function typechecks. ### Additional information about the issue _No response_
Activity
MartinJohns commentedon Dec 6, 2024
This sounds like a duplicate of #52394.
sliminality commentedon Dec 6, 2024
You're totally right, I missed that. Thanks!
satisfieschanges the generic type, "resolves" it immediately #52394