Skip to content

Commit cd68bd4

Browse files
committed
docs: add comments explaining mapped type subtype limitations
Document why mapped types like Required<T>, Pick<T, K> are not shown as subtypes: - Structural subtype checks are expensive and can produce noisy results - Mapped type semantics vary - some create subtypes, some create supertypes
1 parent 22bcb2f commit cd68bd4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/services/typeHierarchy.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,11 @@ function mixinUsesSymbolInChain(callExpr: CallExpression, targetSymbol: Symbol,
920920
* This is true for:
921921
* - Direct references: type Foo = Bar (Foo is an alias for Bar, considered a subtype)
922922
* - Intersection types: type A = B & C (A is a subtype of B and C)
923+
* - Mapped types that produce subtypes: Required<T> is a subtype of T
923924
*
924925
* This is NOT true for:
925926
* - Union types: type A = B | C (A is a SUPERtype of B and C, not a subtype)
927+
* - Mapped types that produce supertypes: Partial<T> is a SUPERtype of T
926928
*/
927929
function typeAliasIsSubtypeOfSymbol(alias: TypeAliasDeclaration, targetSymbol: Symbol, typeChecker: TypeChecker): boolean {
928930
const typeNode = alias.type;
@@ -949,6 +951,11 @@ function typeAliasIsSubtypeOfSymbol(alias: TypeAliasDeclaration, targetSymbol: S
949951
// Union types are NOT subtypes of their members - the relationship is reversed
950952
// type Pet = Dog | Cat means Pet is a SUPERTYPE of Dog (every Dog is a Pet)
951953
// So we don't include union type aliases as subtypes
954+
//
955+
// Note: Mapped types like Required<T>, Pick<T, K> are not included as subtypes
956+
// because the structural subtype check is expensive and can produce noisy results.
957+
// These utility types create new types that may or may not be assignable to the original
958+
// depending on the specific mapped type semantics.
952959

953960
return false;
954961
}

0 commit comments

Comments
 (0)