Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,8 @@ namespace ts {
// Declare a 'member' in case it turns out the container was an ES5 class
if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) {
container.symbol.members = container.symbol.members || {};
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
// It's acceptable for multiple 'this' assignments of the same identifier to occur
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ namespace ts {
}
// Handle module.exports = expr
if (declaration.kind === SyntaxKind.BinaryExpression) {
return links.type = checkExpression((<BinaryExpression>declaration).right);
return links.type = getUnionType(map(symbol.declarations, (decl: BinaryExpression) => checkExpressionCached(decl.right)));
}
if (declaration.kind === SyntaxKind.PropertyAccessExpression) {
// Declarations only exist for property access expressions for certain
Expand Down
14 changes: 14 additions & 0 deletions tests/cases/fourslash/getJavaScriptSemanticDiagnostics23.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

// @allowJs: true
// @Filename: a.js
//// function Person(age) {
//// if (age >= 18) {
//// this.canVote = true;
//// } else {
//// this.canVote = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the resulting type if the assignments are of different (incompatible) types (e.g. a boolean and an arrow function)? Do you get any errors or intellisense off the resulting type?

It would be good to add a test to cover that scenario for both documentation and regression purposes.

EDIT: Per discussion - ideally would be a union type.

//// }
//// }

verify.getSyntacticDiagnostics(`[]`);
verify.getSemanticDiagnostics(`[]`);
16 changes: 16 additions & 0 deletions tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />

// @allowJs: true
// @Filename: a.js
//// function Person(age) {
//// if (age >= 18) {
//// this.canVote = true;
//// } else {
//// this.canVote = 23;
//// }
//// }
//// let x = new Person(100);
//// x.canVote/**/;

goTo.marker();
verify.quickInfoIs('(property) Person.canVote: boolean | number');