Skip to content

Commit 111df34

Browse files
TypeScript BotAndarist
TypeScript Bot
andauthored
🤖 Pick PR #53207 (Fixed symbol declarations for gener...) into release-5.0 (#53271)
Co-authored-by: Mateusz BurzyÅ„ski <[email protected]>
1 parent 1e70bb8 commit 111df34

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

‎src/compiler/checker.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -13179,9 +13179,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1317913179
// and T as the template type.
1318013180
const typeParameter = getTypeParameterFromMappedType(type);
1318113181
const constraintType = getConstraintTypeFromMappedType(type);
13182-
const nameType = getNameTypeFromMappedType(type.target as MappedType || type);
13183-
const isFilteringMappedType = nameType && isTypeAssignableTo(nameType, typeParameter);
13184-
const templateType = getTemplateTypeFromMappedType(type.target as MappedType || type);
13182+
const mappedType = (type.target as MappedType) || type;
13183+
const nameType = getNameTypeFromMappedType(mappedType);
13184+
const shouldLinkPropDeclarations = !nameType || isFilteringMappedType(mappedType);
13185+
const templateType = getTemplateTypeFromMappedType(mappedType);
1318513186
const modifiersType = getApparentType(getModifiersTypeFromMappedType(type)); // The 'T' in 'keyof T'
1318613187
const templateModifiers = getMappedTypeModifiers(type);
1318713188
const include = keyofStringsOnly ? TypeFlags.StringLiteral : TypeFlags.StringOrNumberLiteralOrUnique;
@@ -13227,7 +13228,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1322713228
prop.links.keyType = keyType;
1322813229
if (modifiersProp) {
1322913230
prop.links.syntheticOrigin = modifiersProp;
13230-
prop.declarations = !nameType || isFilteringMappedType ? modifiersProp.declarations : undefined;
13231+
prop.declarations = shouldLinkPropDeclarations ? modifiersProp.declarations : undefined;
1323113232
}
1323213233
members.set(propName, prop);
1323313234
}
@@ -13360,6 +13361,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1336013361
return false;
1336113362
}
1336213363

13364+
function isFilteringMappedType(type: MappedType): boolean {
13365+
const nameType = getNameTypeFromMappedType(type);
13366+
return !!nameType && isTypeAssignableTo(nameType, getTypeParameterFromMappedType(type));
13367+
}
13368+
1336313369
function resolveStructuredTypeMembers(type: StructuredType): ResolvedType {
1336413370
if (!(type as ResolvedType).members) {
1336513371
if (type.flags & TypeFlags.Object) {
@@ -17488,8 +17494,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1748817494
// K is generic and N is assignable to P, instantiate E using a mapper that substitutes the index type for P.
1748917495
// For example, for an index access { [P in K]: Box<T[P]> }[X], we construct the type Box<T[X]>.
1749017496
if (isGenericMappedType(objectType)) {
17491-
const nameType = getNameTypeFromMappedType(objectType);
17492-
if (!nameType || isTypeAssignableTo(nameType, getTypeParameterFromMappedType(objectType))) {
17497+
if (!getNameTypeFromMappedType(objectType) || isFilteringMappedType(objectType)) {
1749317498
return type[cache] = mapType(substituteIndexedMappedType(objectType, type.indexType), t => getSimplifiedType(t, writing));
1749417499
}
1749517500
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
///<reference path="fourslash.ts"/>
2+
3+
//// const obj = {
4+
//// get /*def*/id() {
5+
//// return 1;
6+
//// },
7+
//// name: "test",
8+
//// };
9+
////
10+
//// type Omit2<T, DroppedKeys extends PropertyKey> = {
11+
//// [K in keyof T as Exclude<K, DroppedKeys>]: T[K];
12+
//// };
13+
////
14+
//// declare function omit2<O, Mask extends { [K in keyof O]?: true }>(
15+
//// obj: O,
16+
//// mask: Mask
17+
//// ): Omit2<O, keyof Mask>;
18+
////
19+
//// const obj2 = omit2(obj, {
20+
//// name: true,
21+
//// });
22+
////
23+
//// obj2.[|/*ref*/id|];
24+
25+
verify.goToDefinition("ref", "def");

0 commit comments

Comments
 (0)