microsoft / microsoft/TypeScript
Error not issued when global type is an alias of an object type literal
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript bug-workbench Playground repro and compare the behavior of T[] with Array when global Array is an object type literal. Trace how the compiler handles the global Array alias, array syntax, and assignability. Done means either both forms behave synonymously or the invalid Array type produces a compiler error, with the repro expectations covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100