mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Revert change to getFalsyFlags (#47125)
* Revert change to getFalsyFlags * Add regression test
This commit is contained in:
parent
d4170586f0
commit
06746efbd9
@ -20893,7 +20893,7 @@ namespace ts {
|
||||
// flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns
|
||||
// no flags for all other types (including non-falsy literal types).
|
||||
function getFalsyFlags(type: Type): TypeFlags {
|
||||
return type.flags & TypeFlags.UnionOrIntersection ? getFalsyFlagsOfTypes((type as UnionType).types) :
|
||||
return type.flags & TypeFlags.Union ? getFalsyFlagsOfTypes((type as UnionType).types) :
|
||||
type.flags & TypeFlags.StringLiteral ? (type as StringLiteralType).value === "" ? TypeFlags.StringLiteral : 0 :
|
||||
type.flags & TypeFlags.NumberLiteral ? (type as NumberLiteralType).value === 0 ? TypeFlags.NumberLiteral : 0 :
|
||||
type.flags & TypeFlags.BigIntLiteral ? isZeroBigInt(type as BigIntLiteralType) ? TypeFlags.BigIntLiteral : 0 :
|
||||
|
||||
@ -39,4 +39,22 @@ tests/cases/conformance/types/spread/spreadObjectOrFalsy.ts(10,14): error TS2698
|
||||
...z
|
||||
};
|
||||
}
|
||||
|
||||
// Repro from #47028
|
||||
|
||||
interface DatafulFoo<T> {
|
||||
data: T;
|
||||
}
|
||||
|
||||
class Foo<T extends string> {
|
||||
data: T | undefined;
|
||||
bar() {
|
||||
if (this.hasData()) {
|
||||
this.data.toLocaleLowerCase();
|
||||
}
|
||||
}
|
||||
hasData(): this is DatafulFoo<T> {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +31,24 @@ function g1<T extends {}, A extends { z: (T | undefined) & T }>(a: A) {
|
||||
...z
|
||||
};
|
||||
}
|
||||
|
||||
// Repro from #47028
|
||||
|
||||
interface DatafulFoo<T> {
|
||||
data: T;
|
||||
}
|
||||
|
||||
class Foo<T extends string> {
|
||||
data: T | undefined;
|
||||
bar() {
|
||||
if (this.hasData()) {
|
||||
this.data.toLocaleLowerCase();
|
||||
}
|
||||
}
|
||||
hasData(): this is DatafulFoo<T> {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [spreadObjectOrFalsy.js]
|
||||
@ -69,6 +87,19 @@ function g1(a) {
|
||||
var z = a.z;
|
||||
return __assign({}, z);
|
||||
}
|
||||
var Foo = /** @class */ (function () {
|
||||
function Foo() {
|
||||
}
|
||||
Foo.prototype.bar = function () {
|
||||
if (this.hasData()) {
|
||||
this.data.toLocaleLowerCase();
|
||||
}
|
||||
};
|
||||
Foo.prototype.hasData = function () {
|
||||
return true;
|
||||
};
|
||||
return Foo;
|
||||
}());
|
||||
|
||||
|
||||
//// [spreadObjectOrFalsy.d.ts]
|
||||
@ -81,3 +112,11 @@ declare function f6<T extends object | undefined>(a: T): T;
|
||||
declare function g1<T extends {}, A extends {
|
||||
z: (T | undefined) & T;
|
||||
}>(a: A): (T | undefined) & T;
|
||||
interface DatafulFoo<T> {
|
||||
data: T;
|
||||
}
|
||||
declare class Foo<T extends string> {
|
||||
data: T | undefined;
|
||||
bar(): void;
|
||||
hasData(): this is DatafulFoo<T>;
|
||||
}
|
||||
|
||||
@ -85,3 +85,46 @@ function g1<T extends {}, A extends { z: (T | undefined) & T }>(a: A) {
|
||||
};
|
||||
}
|
||||
|
||||
// Repro from #47028
|
||||
|
||||
interface DatafulFoo<T> {
|
||||
>DatafulFoo : Symbol(DatafulFoo, Decl(spreadObjectOrFalsy.ts, 31, 1))
|
||||
>T : Symbol(T, Decl(spreadObjectOrFalsy.ts, 35, 21))
|
||||
|
||||
data: T;
|
||||
>data : Symbol(DatafulFoo.data, Decl(spreadObjectOrFalsy.ts, 35, 25))
|
||||
>T : Symbol(T, Decl(spreadObjectOrFalsy.ts, 35, 21))
|
||||
}
|
||||
|
||||
class Foo<T extends string> {
|
||||
>Foo : Symbol(Foo, Decl(spreadObjectOrFalsy.ts, 37, 1))
|
||||
>T : Symbol(T, Decl(spreadObjectOrFalsy.ts, 39, 10))
|
||||
|
||||
data: T | undefined;
|
||||
>data : Symbol(Foo.data, Decl(spreadObjectOrFalsy.ts, 39, 29))
|
||||
>T : Symbol(T, Decl(spreadObjectOrFalsy.ts, 39, 10))
|
||||
|
||||
bar() {
|
||||
>bar : Symbol(Foo.bar, Decl(spreadObjectOrFalsy.ts, 40, 24))
|
||||
|
||||
if (this.hasData()) {
|
||||
>this.hasData : Symbol(Foo.hasData, Decl(spreadObjectOrFalsy.ts, 45, 5))
|
||||
>this : Symbol(Foo, Decl(spreadObjectOrFalsy.ts, 37, 1))
|
||||
>hasData : Symbol(Foo.hasData, Decl(spreadObjectOrFalsy.ts, 45, 5))
|
||||
|
||||
this.data.toLocaleLowerCase();
|
||||
>this.data.toLocaleLowerCase : Symbol(String.toLocaleLowerCase, Decl(lib.es5.d.ts, --, --))
|
||||
>this.data : Symbol(data, Decl(spreadObjectOrFalsy.ts, 39, 29), Decl(spreadObjectOrFalsy.ts, 35, 25))
|
||||
>data : Symbol(data, Decl(spreadObjectOrFalsy.ts, 39, 29), Decl(spreadObjectOrFalsy.ts, 35, 25))
|
||||
>toLocaleLowerCase : Symbol(String.toLocaleLowerCase, Decl(lib.es5.d.ts, --, --))
|
||||
}
|
||||
}
|
||||
hasData(): this is DatafulFoo<T> {
|
||||
>hasData : Symbol(Foo.hasData, Decl(spreadObjectOrFalsy.ts, 45, 5))
|
||||
>DatafulFoo : Symbol(DatafulFoo, Decl(spreadObjectOrFalsy.ts, 31, 1))
|
||||
>T : Symbol(T, Decl(spreadObjectOrFalsy.ts, 39, 10))
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -73,3 +73,42 @@ function g1<T extends {}, A extends { z: (T | undefined) & T }>(a: A) {
|
||||
};
|
||||
}
|
||||
|
||||
// Repro from #47028
|
||||
|
||||
interface DatafulFoo<T> {
|
||||
data: T;
|
||||
>data : T
|
||||
}
|
||||
|
||||
class Foo<T extends string> {
|
||||
>Foo : Foo<T>
|
||||
|
||||
data: T | undefined;
|
||||
>data : T | undefined
|
||||
|
||||
bar() {
|
||||
>bar : () => void
|
||||
|
||||
if (this.hasData()) {
|
||||
>this.hasData() : boolean
|
||||
>this.hasData : () => this is DatafulFoo<T>
|
||||
>this : this
|
||||
>hasData : () => this is DatafulFoo<T>
|
||||
|
||||
this.data.toLocaleLowerCase();
|
||||
>this.data.toLocaleLowerCase() : string
|
||||
>this.data.toLocaleLowerCase : (locales?: string | string[] | undefined) => string
|
||||
>this.data : (T | undefined) & T
|
||||
>this : this & DatafulFoo<T>
|
||||
>data : (T | undefined) & T
|
||||
>toLocaleLowerCase : (locales?: string | string[] | undefined) => string
|
||||
}
|
||||
}
|
||||
hasData(): this is DatafulFoo<T> {
|
||||
>hasData : () => this is DatafulFoo<T>
|
||||
|
||||
return true;
|
||||
>true : true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -33,3 +33,21 @@ function g1<T extends {}, A extends { z: (T | undefined) & T }>(a: A) {
|
||||
...z
|
||||
};
|
||||
}
|
||||
|
||||
// Repro from #47028
|
||||
|
||||
interface DatafulFoo<T> {
|
||||
data: T;
|
||||
}
|
||||
|
||||
class Foo<T extends string> {
|
||||
data: T | undefined;
|
||||
bar() {
|
||||
if (this.hasData()) {
|
||||
this.data.toLocaleLowerCase();
|
||||
}
|
||||
}
|
||||
hasData(): this is DatafulFoo<T> {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user