diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 033a0f7b41938..4d60b039dea24 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3524,8 +3524,8 @@ export function isSpecialPropertyDeclaration(expr: PropertyAccessExpression | El export function setValueDeclaration(symbol: Symbol, node: Declaration): void { const { valueDeclaration } = symbol; if (!valueDeclaration || - !(node.flags & NodeFlags.Ambient && !(valueDeclaration.flags & NodeFlags.Ambient)) && - (isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) || + !(node.flags & NodeFlags.Ambient && !(valueDeclaration.flags & NodeFlags.Ambient)) && (isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) || + node.kind === SyntaxKind.PropertyDeclaration && isAssignmentDeclaration(valueDeclaration) || (valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration))) { // other kinds of value declarations take precedence over modules and assignment declarations symbol.valueDeclaration = node; diff --git a/tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline b/tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline new file mode 100644 index 0000000000000..c4da169cb7b3f --- /dev/null +++ b/tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline @@ -0,0 +1,35 @@ +Syntactic Diagnostics for file '/tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts': +/test.js(6,5): error TS8009: The 'declare' modifier can only be used in TypeScript files. +/test.js(6,19): error TS8010: Type annotations can only be used in TypeScript files. + + +==== /test.js (2 errors) ==== + class Foo { + constructor() { + this.prop = { }; + } + + declare prop: string; + ~~~~~~~ +!!! error TS8009: The 'declare' modifier can only be used in TypeScript files. + ~~~~~~ +!!! error TS8010: Type annotations can only be used in TypeScript files. + method() { + this.prop.foo + } + } + +Semantic Diagnostics for file '/tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts': + + +==== /test.js (0 errors) ==== + class Foo { + constructor() { + this.prop = { }; + } + + declare prop: string; + method() { + this.prop.foo + } + } \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts b/tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts new file mode 100644 index 0000000000000..bfbe786e0545a --- /dev/null +++ b/tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts @@ -0,0 +1,18 @@ +/// + +// @noLib: true +// @allowJs: true +// @filename: /test.js +////class Foo { +//// constructor() { +//// this.prop = { }; +//// } +//// +//// declare prop: string; +//// method() { +//// this.prop.foo/**/ +//// } +////} + +verify.baselineQuickInfo(); +verify.baselineSyntacticAndSemanticDiagnostics(); \ No newline at end of file