Skip to content

Commit d7b8025

Browse files
committed
Mapped types like Pick<T, K> should adopt property documentation from T.
Fixes #26430.
1 parent e8b72aa commit d7b8025

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6666,7 +6666,7 @@ namespace ts {
66666666
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
66676667
// We have a { [P in keyof T]: X }
66686668
for (const prop of getPropertiesOfType(modifiersType)) {
6669-
addMemberForKeyType(getLiteralTypeFromPropertyName(prop, include), /*_index*/ undefined, prop);
6669+
addMemberForKeyType(getLiteralTypeFromPropertyName(prop, include));
66706670
}
66716671
if (modifiersType.flags & TypeFlags.Any || getIndexInfoOfType(modifiersType, IndexKind.String)) {
66726672
addMemberForKeyType(stringType);
@@ -6685,7 +6685,7 @@ namespace ts {
66856685
}
66866686
setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
66876687

6688-
function addMemberForKeyType(t: Type, _index?: number, origin?: Symbol) {
6688+
function addMemberForKeyType(t: Type) {
66896689
// Create a mapper from T to the current iteration type constituent. Then, if the
66906690
// mapped type is itself an instantiated type, combine the iteration mapper with the
66916691
// instantiation mapper.
@@ -6707,9 +6707,9 @@ namespace ts {
67076707
prop.type = strictNullChecks && isOptional && !isTypeAssignableTo(undefinedType, propType) ? getOptionalType(propType) :
67086708
strictNullChecks && !isOptional && modifiersProp && modifiersProp.flags & SymbolFlags.Optional ? getTypeWithFacts(propType, TypeFacts.NEUndefined) :
67096709
propType;
6710-
if (origin) {
6711-
prop.syntheticOrigin = origin;
6712-
prop.declarations = origin.declarations;
6710+
if (modifiersProp) {
6711+
prop.syntheticOrigin = modifiersProp;
6712+
prop.declarations = modifiersProp.declarations;
67136713
}
67146714
prop.nameType = t;
67156715
members.set(propName, prop);
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
/// <reference path="./fourslash.ts"/>
22

3-
////interface I { m(): void; }
3+
////interface I {
4+
//// /** m documentation */ m(): void;
5+
////}
46
////declare const o: { [K in keyof I]: number };
57
////o.m/*0*/;
68
////
79
////declare const p: { [K in keyof I]: I[K] };
810
////p.m/*1*/;
11+
////
12+
////declare const q: Pick<I, "m">;
13+
////q.m/*2*/;
914

10-
verify.quickInfoAt("0", "(property) m: number");
11-
verify.quickInfoAt("1", "(method) m(): void");
15+
verify.quickInfoAt("0", "(property) m: number", "m documentation");
16+
verify.quickInfoAt("1", "(method) m(): void", "m documentation");
17+
verify.quickInfoAt("2", "(method) m(): void", "m documentation");

0 commit comments

Comments
 (0)