microsoft / microsoft/TypeScript
Creating too many types for DOM & D3
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Commit 06fe1ed53721862b56c61ebb89b1daee2bc10710 introduced a regression in the number of types created when compiling a snippet of @types\d3. Specifically, it appears to be elaborating types for an error message that ends up getting dropped.
Repro:
{
"compileOnSave": false,
"compilerOptions": {
"alwaysStrict": true,
"noImplicitAny": true,
"noEmit": true,
"lib": [ "es5", "dom" ],
"noResolve": true,
"types": [],
"skipLibCheck": true
},
"files": [
"test.ts",
}
test.ts
declare function select<GElement extends BaseType, OldDatum>(selector: string): Selection2<GElement, OldDatum, HTMLElement, any>;
type BaseType = Element | Document | Window | null | number;
type ValueFn<T extends BaseType, Datum, Result> = (this: T, datum: Datum, index: number, groups: T[] | ArrayLike<T>) => Result;
interface Selection2<GElement extends BaseType, Datum, PElement extends BaseType, PDatum> {
select<DescElement extends BaseType>(selector: ValueFn<GElement, Datum, DescElement>): Selection2<DescElement, Datum, PElement, PDatum>;
}
For an apples-to-apples comparison, use nolib and specify the 3.1 lib.es5.d.ts and lib.dom.d.ts for both compilations.
In round numbers, there are ~150 types without the change and ~2500 types with the change.
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
Reproduce the issue with the provided compilerOptions and test.ts snippet, comparing the roughly 150 versus 2500 type counts using the 3.1 lib.es5.d.ts and lib.dom.d.ts files. Inspect commit 06fe1ed53721862b56c61ebb89b1daee2bc10710 and the compiler's error-message elaboration path. Done means compiling the repro no longer elaborates the discarded error-message types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- d3, typescript
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100