microsoft / microsoft/TypeScript
partial function with generic lost the type constraint
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔎 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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el TypeScript Playground enlazado y la reproducción mínima proporcionada, centrándote en la interacción entre generic partialCall y numChange. Confirma el tipo inferido de machineNumChange y compáralo con el rechazo esperado de la clave 'a'; se considera terminado cuando la función devuelta conserva la restricción de claves de numChange.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 30/100