Open JoshuaKGoldberg opened 1 month ago
FYI, those properties are lazily created by functions within the checker - they're just cache fields, which is why they're optional, and we use functions within the checker to calculate, cache, and access them. Relying on their direct presence is risky.
π 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
, andtypeParameter
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
: