Skip to content

Expose MappedType in typescript.d.tsΒ #59221

Open
@JoshuaKGoldberg

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:

/** @internal */
export interface MappedType extends AnonymousType {
declaration: MappedTypeNode;
typeParameter?: TypeParameter;
constraintType?: Type;
nameType?: Type;
templateType?: Type;
modifiersType?: Type;
resolvedApparentType?: Type;
containsError?: boolean;
}

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 typescript-eslint/typescript-eslint#8173 & typescript-eslint/typescript-eslint#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
}

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions