microsoft / microsoft/TypeScript
Error not issued when global type is an alias of an object type literal
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
array, constructor, bracket
🕗 Version & Regression Information
- This is a crash
⏯ Playground Link
💻 Code
// @noLib: true
// @target: esnext
declare global {
const Array: {
<T = unknown>(...args:any[]): Array<T>
new <T = unknown,>(...args:any[]): Array<T>
}
type Array<T> = {
[i: number]: T
length: number
}
}
// all of the below give "Property 'length' is missing in type '{}'...":
; ([1, 2, 3]) satisfies Array<number>;
; ([1, 2, 3]) satisfies { length: number };
declare const ar1: never[]
; ar1 satisfies { length: number };
declare const ar2: number[]
; ar2 satisfies { length: number }
// this should throw an error but it doesn't
// @ts-expect-error
; ([] as number[]) satisfies string[]
export { }
🙁 Actual behavior
Types created with the T[] and objects created with the [x as T] syntax are not typed as Array<T> but instead as {}.
🙂 Expected behavior
I expect either:
T[]syntax andArray<T>to be completely synonymous- A compiler error that the
Arraytype is not an instantiable type
Additional information about the issue
Related to #57009.
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 la riproduzione collegata in TypeScript bug-workbench Playground e confronta il comportamento di T[] con quello di Array quando global Array è un literal di tipo oggetto. Traccia il modo in cui il compilatore gestisce l'alias globale Array, la sintassi degli array e l'assegnabilità. Il lavoro è completato se entrambe le forme si comportano in modo sinonimo oppure se il tipo Array non valido produce un errore del compilatore, con le aspettative della riproduzione coperte da un test di regressione.
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à
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100