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
5 changes: 4 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18487,7 +18487,10 @@ namespace ts {
}
}
}
else if (strictNullChecks && prop && prop.valueDeclaration && isPropertyAccessExpression(prop.valueDeclaration) && getAssignmentDeclarationPropertyAccessKind(prop.valueDeclaration)) {
else if (strictNullChecks && prop && prop.valueDeclaration &&
isPropertyAccessExpression(prop.valueDeclaration) &&
getAssignmentDeclarationPropertyAccessKind(prop.valueDeclaration) &&
getControlFlowContainer(node) === getControlFlowContainer(prop.valueDeclaration)) {
assumeUninitialized = true;
}
const flowType = getFlowTypeOfReference(node, propType, assumeUninitialized ? getOptionalType(propType) : propType);
Expand Down
34 changes: 34 additions & 0 deletions tests/baselines/reference/typeFromPropertyAssignment37.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
=== tests/cases/conformance/salsa/use.js ===
const util = require('./mod')
>util : Symbol(util, Decl(use.js, 0, 5))
>require : Symbol(require)
>'./mod' : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))

function n() {
>n : Symbol(n, Decl(use.js, 0, 29))

util.existy // no error
>util.existy : Symbol(existy, Decl(mod.js, 1, 14))
>util : Symbol(util, Decl(use.js, 0, 5))
>existy : Symbol(existy, Decl(mod.js, 1, 14))
}
util.existy // no error
>util.existy : Symbol(existy, Decl(mod.js, 1, 14))
>util : Symbol(util, Decl(use.js, 0, 5))
>existy : Symbol(existy, Decl(mod.js, 1, 14))

=== tests/cases/conformance/salsa/mod.js ===
const util = exports = module.exports = {}
>util : Symbol(util, Decl(mod.js, 0, 5))
>exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
>module.exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))
>module : Symbol(module, Decl(mod.js, 0, 22))
>exports : Symbol("tests/cases/conformance/salsa/mod", Decl(mod.js, 0, 0))

if (!!false) {
util.existy = function () { }
>util.existy : Symbol(existy, Decl(mod.js, 1, 14))
>util : Symbol(util, Decl(mod.js, 0, 5))
>existy : Symbol(existy, Decl(mod.js, 1, 14))
}

44 changes: 44 additions & 0 deletions tests/baselines/reference/typeFromPropertyAssignment37.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
=== tests/cases/conformance/salsa/use.js ===
const util = require('./mod')
>util : typeof import("tests/cases/conformance/salsa/mod")
>require('./mod') : typeof import("tests/cases/conformance/salsa/mod")
>require : any
>'./mod' : "./mod"

function n() {
>n : () => void

util.existy // no error
>util.existy : () => void
>util : typeof import("tests/cases/conformance/salsa/mod")
>existy : () => void
}
util.existy // no error
>util.existy : () => void
>util : typeof import("tests/cases/conformance/salsa/mod")
>existy : () => void

=== tests/cases/conformance/salsa/mod.js ===
const util = exports = module.exports = {}
>util : typeof import("tests/cases/conformance/salsa/mod")
>exports = module.exports = {} : typeof import("tests/cases/conformance/salsa/mod")
>exports : typeof import("tests/cases/conformance/salsa/mod")
>module.exports = {} : typeof import("tests/cases/conformance/salsa/mod")
>module.exports : typeof import("tests/cases/conformance/salsa/mod")
>module : { "tests/cases/conformance/salsa/mod": typeof import("tests/cases/conformance/salsa/mod"); }
>exports : typeof import("tests/cases/conformance/salsa/mod")
>{} : {}

if (!!false) {
>!!false : boolean
>!false : true
>false : false

util.existy = function () { }
>util.existy = function () { } : () => void
>util.existy : () => void
>util : typeof import("tests/cases/conformance/salsa/mod")
>existy : () => void
>function () { } : () => void
}

15 changes: 15 additions & 0 deletions tests/cases/conformance/salsa/typeFromPropertyAssignment37.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: mod.js
const util = exports = module.exports = {}
if (!!false) {
util.existy = function () { }
}

// @Filename: use.js
const util = require('./mod')
function n() {
util.existy // no error
}
util.existy // no error