microsoft / microsoft/TypeScript
Allow users to customize the variance of built-in `Array`
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
Array covariance hardcoded?, Array invariance, --noLib
🕗 Version & Regression Information
Tested with 4.9.5
⏯ Playground Link
💻 Code
// @noLib: true
interface Array<T>
{ [i: number]: T | undefined
, push: (t: T) => number
}
interface _Array<T>
{ [i: number]: T | undefined
, push: (t: T) => number
}
declare let as: Array<"a">
declare let abs: Array<"a" | "b">
abs = as
declare let _as: _Array<"a">
declare let _abs: _Array<"a" | "b">
_abs = _as
🙁 Actual behavior
The assignment abs = as compiles.
🙂 Expected behavior
The assignment abs = as should not compile, just like the assignment _abs = _as does not compile.
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 by reproducing the TypeScript Playground example linked in the issue, especially the comparison between built-in Array and _Array under @noLib. Trace how the compiler handles variance for the built-in Array, then verify that abs = as is rejected like _abs = _as without changing the demonstrated custom-interface behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100