microsoft / microsoft/TypeScript

Expose MappedType in typescript.d.ts

Open
#59,221 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔍 Search Terms

mappedtype interface typeParameter constraintType templateType

✅ Viability Checklist
⭐ Suggestion

Coming over from typescript-eslint, we need to look at the properties on mapped types for the @typescript-eslint/no-unnecessary-type-parameters ("Golden Rule of Generics") rule. But, MappedType is marked as @internal in TypeScript's definition:

https://github.com/microsoft/TypeScript/blob/22bbe867fd4b86e2187270f6c284e6cfd92a3fea/src/compiler/types.ts#L6584-L6594

Could we have that interface be public, please? Even if all the fields other than constraintType, templateType, and typeParameter are switched to @internal. I don't know of a more sanctioned way to access those type properties. Is there one?

📃 Motivating Example

Marking MappedType as public would provide a way for type checker API consumers to reason about mapped types.

💻 Use Cases

See https://github.com/typescript-eslint/typescript-eslint/pull/8173 & https://github.com/typescript-eslint/typescript-eslint/pull/9530: in typescript-eslint, we need to access a few properties of mapped types to check if they're uses of a type parameter. We ended up writing our own interface MappedType extends ts.ObjectType:

interface MappedType extends ts.ObjectType {
  typeParameter?: ts.Type; // #8173
  constraintType?: ts.Type; // #9530
  templateType?: ts.Type; // #9530
}

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

Start with src/compiler/types.ts around the internal MappedType interface and compare its current fields with the requested public API. Review the linked typescript-eslint rule examples to understand the consumers’ needs. Done means MappedType is exposed through typescript.d.ts with the requested typeParameter, constraintType, and templateType access.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.