Generic indexed access on a substitution type with an array constraint resolves incorrectly
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 38/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- typescript
- Ambito
- compilers
Direzione di ricerca
Inizia con la riproduzione collegata in TypeScript Playground e confronta il ramo generico di accesso indicizzato che fallisce con la variante funzionante che aggiunge un alias di tipo array. Leggi il comportamento discusso in PR 48837, quindi verifica che l’esempio originale non segnali più l’errore di vincolo, preservando il comportamento previsto del tipo mappato inferito.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🔎 Search Terms
indexed access substitution type array constraint
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type LiteralType = string | number | boolean;
type ValueGetter<ValueType extends LiteralType = LiteralType> = () => ValueType;
type Schema = SchemaArray | SchemaObject | LiteralType;
type SchemaArray = Array<SchemaObject | SchemaArray | LiteralType>;
type SchemaObject = {
[key: string]: SchemaObject | SchemaArray | LiteralType;
};
type InferValuesFromSchema<S extends Schema> = S extends LiteralType
? ValueGetter<S>
: S extends SchemaArray
? {
[K in keyof S]: InferValuesFromSchema<S[K]>;
}
: S extends SchemaObject
? {
[K in keyof S]: InferValuesFromSchema<S[K]>;
}
: never;
🙁 Actual behavior
an error is reported:
Type 'S[K]' does not satisfy the constraint 'Schema'.
Type 'S[keyof S]' is not assignable to type 'Schema'.
Type 'S[string] | S[number] | S[symbol]' is not assignable to type 'Schema'.
Type 'S[string]' is not assignable to type 'Schema'.
Type 'S[string]' is not assignable to type 'SchemaObject'.
Type 'S[keyof S]' is not assignable to type 'SchemaObject'.
Type 'S[K]' is not assignable to type 'SchemaObject'.
Type 'S[keyof S]' is not assignable to type 'SchemaObject'.
Type 'S[string] | S[number] | S[symbol]' is not assignable to type 'SchemaObject'.
Type 'S[string]' is not assignable to type 'SchemaObject'.(2344)
🙂 Expected behavior
There should be no error, S[K] should satisfy Schema constraint (at least since https://github.com/microsoft/TypeScript/pull/48837 )
Additional information about the issue
A variant with an additional type alias for that array branch works OK: TS playground.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/TypeScript
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
microsoft/TypeScript#64322 · 2 commenti · 1 reazione · 2 assegnatari ·
-
Possible Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/TypeScript#64278 · 1 commento · 1 reazione ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
microsoft/TypeScript#64118 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
microsoft/TypeScript#64094 ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/TypeScript#63959 · 5 commenti ·
Tutte le issue di microsoft/TypeScript
Issue simili
-
optimization optimization:agents-md-curator
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
blinklabs-io/bursa#904 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 commenti ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100