mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Co-authored-by: Ryan Cavanaugh <RyanCavanaugh@users.noreply.github.com>
This commit is contained in:
parent
6212132b83
commit
1a03e5340a
@ -39725,6 +39725,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.YieldExpression:
|
||||
case SyntaxKind.ThisKeyword:
|
||||
return PredicateSemantics.Sometimes;
|
||||
case SyntaxKind.BinaryExpression:
|
||||
// List of operators that can produce null/undefined:
|
||||
|
||||
@ -73,4 +73,8 @@ predicateSemantics.ts(36,8): error TS2872: This kind of expression is always tru
|
||||
|
||||
// Should be OK
|
||||
console.log((cond || undefined) && 1 / cond);
|
||||
|
||||
|
||||
function foo(this: Object | undefined) {
|
||||
// Should be OK
|
||||
return this ?? 0;
|
||||
}
|
||||
@ -40,7 +40,11 @@ while ((({}))) { }
|
||||
|
||||
// Should be OK
|
||||
console.log((cond || undefined) && 1 / cond);
|
||||
|
||||
|
||||
function foo(this: Object | undefined) {
|
||||
// Should be OK
|
||||
return this ?? 0;
|
||||
}
|
||||
|
||||
//// [predicateSemantics.js]
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
@ -80,3 +84,7 @@ while (({})) { }
|
||||
while ((({}))) { }
|
||||
// Should be OK
|
||||
console.log((cond || undefined) && 1 / cond);
|
||||
function foo() {
|
||||
// Should be OK
|
||||
return this !== null && this !== void 0 ? this : 0;
|
||||
}
|
||||
|
||||
@ -70,3 +70,12 @@ console.log((cond || undefined) && 1 / cond);
|
||||
>undefined : Symbol(undefined)
|
||||
>cond : Symbol(cond, Decl(predicateSemantics.ts, 0, 11))
|
||||
|
||||
function foo(this: Object | undefined) {
|
||||
>foo : Symbol(foo, Decl(predicateSemantics.ts, 38, 45))
|
||||
>this : Symbol(this, Decl(predicateSemantics.ts, 40, 13))
|
||||
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
// Should be OK
|
||||
return this ?? 0;
|
||||
>this : Symbol(this, Decl(predicateSemantics.ts, 40, 13))
|
||||
}
|
||||
|
||||
@ -219,3 +219,18 @@ console.log((cond || undefined) && 1 / cond);
|
||||
>cond : any
|
||||
> : ^^^
|
||||
|
||||
function foo(this: Object | undefined) {
|
||||
>foo : (this: Object | undefined) => Object | 0
|
||||
> : ^ ^^ ^^^^^^^^^^^^^^^
|
||||
>this : Object
|
||||
> : ^^^^^^
|
||||
|
||||
// Should be OK
|
||||
return this ?? 0;
|
||||
>this ?? 0 : 0 | Object
|
||||
> : ^^^^^^^^^^
|
||||
>this : Object
|
||||
> : ^^^^^^
|
||||
>0 : 0
|
||||
> : ^
|
||||
}
|
||||
|
||||
@ -37,3 +37,8 @@ while ((({}))) { }
|
||||
|
||||
// Should be OK
|
||||
console.log((cond || undefined) && 1 / cond);
|
||||
|
||||
function foo(this: Object | undefined) {
|
||||
// Should be OK
|
||||
return this ?? 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user