microsoft / microsoft/TypeScript
`satisfies` changes the generic type, "resolves" it immediately
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
It seems that using satisfies on a value that is bound to a generic type, in some way resolves the generic type at that place.
const foo = <T extends 1 | 2>(bar: T) => {
// PROBLEM: a and b should have the same type.
const a = bar satisfies any; // using any type that doesn't use the generic T here creates this problem
// ^? 1 | 2
const b = bar;
// ^? T extends 1 | 2
}
🔎 Search Terms
satisfies changes type, generic, widening
🕗 Version & Regression Information
Using 4.9.4 now with satisfies and noticed this.
- This changed between versions 4.9 and 4.8 when satisfies was introduced
- This is the behavior in every version I tried, and I reviewed the FAQ
- I was unable to test this on prior versions because satisfies didn't exist
⏯ Playground Link
🙁 Actual behavior
a and b have different types as seen in the playground
🙂 Expected behavior
satisfies should be a no-op
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the generic satisfies example in the linked TypeScript Playground and compare the inferred types of a and b. Trace the compiler's handling of satisfies expressions involving generic values; done means both variables retain the same generic type rather than resolving a to 1 | 2, with a regression test covering the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100