microsoft / microsoft/TypeScript
Type 'any' cannot be used as an index type silently fails when used in generics (TS2538)
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
TS2538 ts2538 silently fails
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about ts2538
⏯ Playground Link
💻 Code
type MyType = [{foo: string}] | {bar: number};
// This errors with type 'any' cannot be used as an index type
type ShouldError = MyType[any];
// This does not error and silently creates an any
type DoSomething<T extends MyType> = T[any];
type WillBeAny = DoSomething<MyType>;
🙁 Actual behavior
When using a generic type, typescript fails to error with error TS2538 which should say that type 'any' cannot be used as an index type, instead, it does not errors and silently turns the type indexed in [any] to a any itself.
🙂 Expected behavior
I would expect typescript compilation to fail as it does when you directly access a type with any (in the example above as MyType[any] )
Additional information about the issue
This seems to be an issue from all versions I tested (several > 3.3). But I did not found an issue acknowledging this is either expected or indeed a bug.
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.
Direzione di ricerca
Inizia con il TypeScript Playground collegato e la riproduzione fornita con MyType, ShouldError e DoSomething. Confronta l'accesso indicizzato generico con la gestione diretta di MyType[any] nel type checker. Il lavoro è completato quando il caso generico segnala TS2538 invece di produrre silenziosamente any, con una copertura di regressione per entrambi i casi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100