microsoft / microsoft/TypeScript
Infer declarations are allowed in generic constraints, but do not infer generic constraint types
Open
Nobody has claimed this yet.
Bug
Domain: check: Type Inference
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 4.0.2
Search Terms: generic constraint, extends infer
Code
type InferGenericConstraint<Fn> =
Fn extends <T extends infer Constraint>(arg: T) => any
? Constraint
: never;
type GenericFunctionExample = <T extends number>(arg: T) => void;
type InferredConstraint = InferGenericConstraint<GenericFunctionExample>;
Expected behavior:
- Preferred:
InferredConstraintisnumber. - Alternative:
inferdeclaration is disallowed within a generic constraint clause.
Actual behavior: InferredConstraint is never
Playground Link: https://tsplay.dev/gWoYlN
Related Issues: #1213
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 provided code in the linked TypeScript Playground using the reported 4.0.2 behavior and compare it with the Nightly version. The issue is done when the inferred constraint is number, or when infer declarations in generic constraint clauses are rejected consistently; no repository file or test is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100