microsoft / microsoft/TypeScript
Fast path opportunity in `checkVariableLikeDeclaration`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
I noticed that for this code:
class A {
state = { foo: "foo", bar: 42 };
}
checkVariableLikeDeclaration calls checkTypeAssignableToAndOptionallyElaborate here:
https://github.dev/microsoft/TypeScript/blob/e9868e96e87996df46a13b4323866acc639e71ce/src/compiler/checker.ts#L40690
This is likely redundant for cases without a declared type as it's guaranteed that this has to return true. I thought at first that this would rely on a fast past based on the type.id but it seems that those types have different ids (perhaps one is fresh while the other one isn't or something?).
I'm happy to explore this optimization. But perhaps you'd have some preferences as to at which level this should be applied?
cc @jakebailey
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 in src/compiler/checker.ts at checkVariableLikeDeclaration and its call to checkTypeAssignableToAndOptionallyElaborate. Use the class-field example from the issue to investigate whether the check is redundant when no declared type is present and whether the differing type IDs matter. Confirm the optimization's behavior and measure whether it improves this path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100