microsoft / microsoft/TypeScript
partial function with generic lost the type constraint
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
generic
partial function with generic lose the type constraint
🕗 Version & Regression Information
- This is a crash
- This changed between versions nightly__ and 4.x___
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about ___ generic, lose type______
- I was unable to test this on prior versions because the version lower than 4.0 do not support tailargs___
⏯ Playground Link
💻 Code
// minimal reproduce
type Arr = readonly any[]
function partialCall<T extends Arr, U extends Arr, R>(
f: (...args: [...T, ...U]) => R,
...headArgs: T
) {
return (...tailArgs: U) => f(...headArgs, ...tailArgs)
}
const machine={
price: 30,
age:10
}
function numChange<T extends Record<string, number>>( obj:T, key: keyof T, delta: number){
return obj[key]+delta
}
const test = numChange(machine , 'age', 10)
// @ts-expect-error
const test1 = numChange(machine,'a',10 ,)
const machineNumChange= partialCall(numChange, machine)
// should i see a error here ?
const te1= machineNumChange('a',20)
🙁 Actual behavior
I'm using a partial function with passing another generic function , the returned function loses the type restrictions on its parameters.
🙂 Expected behavior
the returned function have the type restrictions on its parameters
Additional information about the issue
No response
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 with the linked TypeScript Playground and the supplied minimal reproduction, focusing on the generic partialCall and numChange interaction. Confirm the inferred type of machineNumChange and compare it with the expected rejection of the 'a' key; done means the returned function preserves numChange's key constraint.
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