Skip to content

Commit 7a65825

Browse files
Merge pull request #26431 from mattmccutchen/issue-26430
Mapped types like Pick<T, K> should adopt property documentation from T.
2 parents 2ee4cee + d7b8025 commit 7a65825

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
@@ -6649,7 +6649,7 @@ namespace ts {
66496649
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
66506650
// We have a { [P in keyof T]: X }
66516651
for (const prop of getPropertiesOfType(modifiersType)) {
6652-
addMemberForKeyType(getLiteralTypeFromPropertyName(prop, include), /*_index*/ undefined, prop);
6652+
addMemberForKeyType(getLiteralTypeFromPropertyName(prop, include));
66536653
}
66546654
if (modifiersType.flags & TypeFlags.Any || getIndexInfoOfType(modifiersType, IndexKind.String)) {
66556655
addMemberForKeyType(stringType);
@@ -6668,7 +6668,7 @@ namespace ts {
66686668
}
66696669
setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
66706670

6671-
function addMemberForKeyType(t: Type, _index?: number, origin?: Symbol) {
6671+
function addMemberForKeyType(t: Type) {
66726672
// Create a mapper from T to the current iteration type constituent. Then, if the
66736673
// mapped type is itself an instantiated type, combine the iteration mapper with the
66746674
// instantiation mapper.
@@ -6690,9 +6690,9 @@ namespace ts {
66906690
prop.type = strictNullChecks && isOptional && !isTypeAssignableTo(undefinedType, propType) ? getOptionalType(propType) :
66916691
strictNullChecks && !isOptional && modifiersProp && modifiersProp.flags & SymbolFlags.Optional ? getTypeWithFacts(propType, TypeFacts.NEUndefined) :
66926692
propType;
6693-
if (origin) {
6694-
prop.syntheticOrigin = origin;
6695-
prop.declarations = origin.declarations;
6693+
if (modifiersProp) {
6694+
prop.syntheticOrigin = modifiersProp;
6695+
prop.declarations = modifiersProp.declarations;
66966696
}
66976697
prop.nameType = t;
66986698
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)