@@ -107,7 +107,12 @@ namespace ts {
107107
108108 getJsxElementAttributesType,
109109 getJsxIntrinsicTagNames,
110- isOptionalParameter
110+ isOptionalParameter,
111+ tryFindAmbientModuleWithoutAugmentations: moduleName => {
112+ // we deliberately exclude augmentations
113+ // since we are only interested in declarations of the module itself
114+ return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
115+ }
111116 };
112117
113118 const tupleTypes: GenericType[] = [];
@@ -1370,16 +1375,11 @@ namespace ts {
13701375 return;
13711376 }
13721377
1373- const isRelative = isExternalModuleNameRelative(moduleName);
1374- const quotedName = '"' + moduleName + '"';
1375- if (!isRelative) {
1376- const symbol = getSymbol(globals, quotedName, SymbolFlags.ValueModule);
1377- if (symbol) {
1378- // merged symbol is module declaration symbol combined with all augmentations
1379- return getMergedSymbol(symbol);
1380- }
1378+ const ambientModule = tryFindAmbientModule(moduleName, /*withAugmentations*/ true);
1379+ if (ambientModule) {
1380+ return ambientModule;
13811381 }
1382-
1382+ const isRelative = isExternalModuleNameRelative(moduleName);
13831383 const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReference);
13841384 const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
13851385 const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
@@ -4762,6 +4762,15 @@ namespace ts {
47624762 }
47634763 }
47644764
4765+ function tryFindAmbientModule(moduleName: string, withAugmentations: boolean) {
4766+ if (isExternalModuleNameRelative(moduleName)) {
4767+ return undefined;
4768+ }
4769+ const symbol = getSymbol(globals, `"${moduleName}"`, SymbolFlags.ValueModule);
4770+ // merged symbol is module declaration symbol combined with all augmentations
4771+ return symbol && withAugmentations ? getMergedSymbol(symbol) : symbol;
4772+ }
4773+
47654774 function isOptionalParameter(node: ParameterDeclaration) {
47664775 if (hasQuestionToken(node) || isJSDocOptionalParameter(node)) {
47674776 return true;
@@ -6908,6 +6917,27 @@ namespace ts {
69086917 }
69096918 }
69106919
6920+ if (target.flags & TypeFlags.TypeParameter) {
6921+ // Given a type parameter K with a constraint keyof T, a type S is
6922+ // assignable to K if S is assignable to keyof T.
6923+ const constraint = getConstraintOfTypeParameter(<TypeParameter>target);
6924+ if (constraint && constraint.flags & TypeFlags.Index) {
6925+ if (result = isRelatedTo(source, constraint, reportErrors)) {
6926+ return result;
6927+ }
6928+ }
6929+ }
6930+ else if (target.flags & TypeFlags.Index) {
6931+ // Given a type parameter T with a constraint C, a type S is assignable to
6932+ // keyof T if S is assignable to keyof C.
6933+ const constraint = getConstraintOfTypeParameter((<IndexType>target).type);
6934+ if (constraint) {
6935+ if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) {
6936+ return result;
6937+ }
6938+ }
6939+ }
6940+
69116941 if (source.flags & TypeFlags.TypeParameter) {
69126942 let constraint = getConstraintOfTypeParameter(<TypeParameter>source);
69136943
@@ -11632,6 +11662,21 @@ namespace ts {
1163211662 diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo));
1163311663 }
1163411664
11665+ function markPropertyAsReferenced(prop: Symbol) {
11666+ if (prop &&
11667+ noUnusedIdentifiers &&
11668+ (prop.flags & SymbolFlags.ClassMember) &&
11669+ prop.valueDeclaration && (getModifierFlags(prop.valueDeclaration) & ModifierFlags.Private)) {
11670+ if (prop.flags & SymbolFlags.Instantiated) {
11671+ getSymbolLinks(prop).target.isReferenced = true;
11672+
11673+ }
11674+ else {
11675+ prop.isReferenced = true;
11676+ }
11677+ }
11678+ }
11679+
1163511680 function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) {
1163611681 const type = checkNonNullExpression(left);
1163711682 if (isTypeAny(type) || type === silentNeverType) {
@@ -11651,17 +11696,7 @@ namespace ts {
1165111696 return unknownType;
1165211697 }
1165311698
11654- if (noUnusedIdentifiers &&
11655- (prop.flags & SymbolFlags.ClassMember) &&
11656- prop.valueDeclaration && (getModifierFlags(prop.valueDeclaration) & ModifierFlags.Private)) {
11657- if (prop.flags & SymbolFlags.Instantiated) {
11658- getSymbolLinks(prop).target.isReferenced = true;
11659-
11660- }
11661- else {
11662- prop.isReferenced = true;
11663- }
11664- }
11699+ markPropertyAsReferenced(prop);
1166511700
1166611701 getNodeLinks(node).resolvedSymbol = prop;
1166711702
@@ -16453,6 +16488,7 @@ namespace ts {
1645316488 const parentType = getTypeForBindingElementParent(parent);
1645416489 const name = node.propertyName || <Identifier>node.name;
1645516490 const property = getPropertyOfType(parentType, getTextOfPropertyName(name));
16491+ markPropertyAsReferenced(property);
1645616492 if (parent.initializer && property && getParentOfSymbol(property)) {
1645716493 checkClassPropertyAccess(parent, parent.initializer, parentType, property);
1645816494 }
0 commit comments