Strange behavior of types while using nested mapped types and generics
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- 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 enlace proporcionado de TypeScript Playground y el ejemplo del constructor de objetos anidados, comparando el tipo inferido de test con las declaraciones independientes de n y p. Sigue cómo las llamadas genéricas anidadas infieren tipos OptionalyProped; se considera terminado cuando las propiedades n anidadas infieren consistentemente OptionalyProped<number> y las propiedades p conservan OptionalyProped<21>.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug Report
I got two differents typings while nesting objects using some object-builder functions and generic optional typings, keeping it quite basic.
These two typings show up in a one-in-two pattern as we dig into the nested objects.
The second one matches with the type of the object-builder.
It can be a misuse of mine so let me know ...
🔎 Search Terms
- mapped type
- nested
- partial optional
- generic
🕗 Version & Regression Information
Typescript versions 5.1.4 & 5.2.0-dev.20230625 & 4.1.6
Just discovered it, so AFAIK this is not a regression.
⏯ Playground Link
💻 Code
type OptionalyProped<OPTL extends number> = { optlValue?: OPTL }
export const optionalyProped = <OPTL extends number>(proped: OptionalyProped<OPTL>): OptionalyProped<OPTL> => proped
type ObjectOfProped<T extends { [key: string]: ObjectOrProped }> = { structure: T }
export const objectOfProped = <OBJ extends { [key: string]: ObjectOrProped }>(
objectOf: ObjectOfProped<OBJ>
): ObjectOfProped<OBJ> => objectOf
type ObjectOrProped = ObjectOfProped<any> | OptionalyProped<any>
const test = objectOfProped({
structure: {
n: optionalyProped({}),
p: optionalyProped({ optlValue: 21}),
o: objectOfProped({
structure: {
n: optionalyProped({}),
p: optionalyProped({ optlValue: 21}),
o: objectOfProped({
structure: {
n: optionalyProped({}),
p: optionalyProped({ optlValue: 21}),
o: objectOfProped({
structure: {
n: optionalyProped({}),
p: optionalyProped({ optlValue: 21}),
},
}),
},
}),
},
}),
},
})
const n = optionalyProped({ }) // typed: OptionalyProped<number>
const p = optionalyProped({ optlValue: 21 }) // typed: OptionalyProped<21>
🙁 Actual behavior
typeof test = ObjectOfProped<{
n: OptionalyProped<any>; // first behavior
p: OptionalyProped<number>;
o: ObjectOfProped<{
n: OptionalyProped<number>; // second behavior (legit one)
p: OptionalyProped<21>;
o: ObjectOfProped<{
n: OptionalyProped<any>;
p: OptionalyProped<number>;
o: ObjectOfProped<{
n: OptionalyProped<number>;
p: OptionalyProped<21>;
}>;
}>;
}>;
}>
🙂 Expected behavior
typeof test = ObjectOfProped<{
n: OptionalyProped<number>; // always
p: OptionalyProped<21>;
o: ObjectOfProped<{
n: OptionalyProped<number>; // the same
p: OptionalyProped<21>;
o: ObjectOfProped<{
n: OptionalyProped<number>; // type
p: OptionalyProped<21>;
o: ObjectOfProped<{
n: OptionalyProped<number>;
p: OptionalyProped<21>;
}>;
}>;
}>;
}>
Thanks
- 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
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
milvus-io/birdwatcher#545 ·
-
kind/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
kubernetes-sigs/prow#953 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
caddyserver/caddy#8046 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
jaegertracing/jaeger#9588 ·