Description
π Search Terms
mappedtype interface typeParameter constraintType templateType
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β 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:
TypeScript/src/compiler/types.ts
Lines 6584 to 6594 in 22bbe86
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
}