microsoft / microsoft/TypeScript

Creating too many types for DOM & D3

Open
#34,586 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Performance
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.