Strange behavior of types while using nested mapped types and generics
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- typescript
- Bereich
- compilers
Rechercherichtung
Beginne mit dem bereitgestellten TypeScript Playground-Link und dem Beispiel für den Builder eines verschachtelten Objekts und vergleiche den inferierten Typ von test mit den eigenständigen Deklarationen von n und p. Verfolge, wie verschachtelte generische Aufrufe OptionalyProped-Typen inferieren; fertig ist die Aufgabe, wenn die verschachtelten n-Eigenschaften durchgängig OptionalyProped<number> inferieren und die p-Eigenschaften OptionalyProped<21> beibehalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microsoft/TypeScript
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
microsoft/TypeScript#64322 · 2 Kommentare · 1 Reaktion · 2 zugewiesene Personen ·
-
Possible Improvement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
microsoft/TypeScript#64278 · 1 Kommentar · 1 Reaktion ·
-
Docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
microsoft/TypeScript#64118 · 1 Kommentar ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
microsoft/TypeScript#64094 ·
-
Docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
microsoft/TypeScript#63959 · 5 Kommentare ·
Alle Issues in microsoft/TypeScript
Ähnliche Issues
-
optimization optimization:agents-md-curator
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
githubnext/gh-aw-cao#13143 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
blinklabs-io/bursa#904 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 Kommentare ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100