`keyof T['prop']` becomes never when the object contains a context-sensitive function
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- typescript
- Área
- compilers
Línea de trabajo
Comienza con el TypeScript Playground enlazado y reproduce el ejemplo recursivo Type<TAcceptedKeys, TType>. Compara los tipos inferidos y los diagnósticos cuando triggerFn no tiene parámetros frente a cuando tiene un parámetro, especialmente para keys y shouldBeKeyofTType. Se considera completado cuando el parámetro de la función ya no cambia inesperadamente los tipos keyof resultantes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug Report
🔎 Search Terms
Not sure how to put this but:
- recursive type
- function
- parameter
- generics
🕗 Version & Regression Information
Tested on these versions:
- typescript@5.1.3
- typescript@5.2.0-dev.20230716 dev
⏯ Playground Link
Code
type Type<
TAcceptedKeys extends string,
TType extends Type<TAcceptedKeys>=any
> = {
/**
* We're using the keys of this property, that is why
* we use a recursive type.
*/
obj?: Record<TAcceptedKeys, 1>
/**
* Just for the sake of illustration.
* In the circumstances of the bug this will be never[].
*/
keys: (keyof TType['obj'])[]
/**
* A function with a parameter inside the recursive type.
* This triggers the bug.
*/
triggerFn?: (param: number) => void
/**
* This will always be TType, regardless of whether
* a parameter is declared in `triggerFn` or not.
*/
shouldBeTType?: TType
/**
* This will be `keyof TType` as expected if a parameter
* is not declared in triggerFn, but it will turn to `undefined`
* as soon as a parameter is declared in that function.
*
* If the below property is passed to defineType
* the type will be as expected:
* triggerFn: () => {}
*
* However this will trigger the bug:
* triggerFn: (param) => {}
*/
shouldBeKeyofTType?: keyof TType
}
const defineType = <TAcceptedKeys extends string>() =>
<const TType extends Type<TAcceptedKeys, TType>>(type: TType) => type
defineType<'apple' | 'banana'>()({
obj: {
apple: 1,
banana: 1
},
keys: [
'apple'
],
/**
* Toggle these comments to see how the bug works.
*/
triggerFn: () => {}, // won't produce diagnostics
// triggerFn: (param) => {}, // type 'string' is not assignable to type 'never'
/**
* Toggle these comments to see diagnostics information.
*/
// shouldBeTType: null,
// shouldBeKeyofTType: null
})
🙁 Actual behavior
The presence or absence of a parameter in an object member function has effect on this object type in certain circumstances.
🙂 Expected behavior
It shouldn't.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
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.
Más de microsoft/TypeScript
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
microsoft/TypeScript#64322 · 2 comentarios · 1 reacción · 2 asignados ·
-
Possible Improvement
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
microsoft/TypeScript#64278 · 1 comentario · 1 reacción ·
-
Docs
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
microsoft/TypeScript#64118 · 1 comentario ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
microsoft/TypeScript#64094 ·
-
Docs
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
microsoft/TypeScript#63959 · 5 comentarios ·
Todos los issues de microsoft/TypeScript
Issues similares
-
optimization optimization:agents-md-curator
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
githubnext/gh-aw-cao#13143 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
blinklabs-io/bursa#904 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 comentarios ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100