Strange behavior of types while using nested mapped types and generics
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- typescript
- Domaine
- compilers
Piste de recherche
Commencez par le lien TypeScript Playground fourni et l’exemple de constructeur d’objet imbriqué, en comparant le type inféré de test avec les déclarations autonomes de n et p. Suivez la manière dont les appels génériques imbriqués infèrent les types OptionalyProped ; le travail est terminé lorsque les propriétés n imbriquées infèrent systématiquement OptionalyProped<number> et que les propriétés p conservent OptionalyProped<21>.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de microsoft/TypeScript
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
microsoft/TypeScript#64322 · 2 commentaires · 1 réaction · 2 personnes assignées ·
-
Possible Improvement
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
microsoft/TypeScript#64278 · 1 commentaire · 1 réaction ·
-
Docs
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
microsoft/TypeScript#64118 · 1 commentaire ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
microsoft/TypeScript#64094 ·
-
Docs
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
microsoft/TypeScript#63959 · 5 commentaires ·
Toutes les issues de microsoft/TypeScript
Issues similaires
-
optimization optimization:agents-md-curator
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
blinklabs-io/bursa#904 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 commentaires ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100