This commit is contained in:
Anders Hejlsberg 2024-02-29 16:19:44 -08:00
Родитель a4ff6b4d87
Коммит 869422f2a5
2 изменённых файлов: 5 добавлений и 10 удалений

Просмотреть файл

@ -14,11 +14,9 @@ inferTypePredicates.ts(113,7): error TS2322: Type 'string | number' is not assig
inferTypePredicates.ts(115,7): error TS2322: Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
inferTypePredicates.ts(205,7): error TS2741: Property 'z' is missing in type 'C1' but required in type 'C2'.
inferTypePredicates.ts(252,7): error TS2322: Type 'string | number | Date' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
==== inferTypePredicates.ts (11 errors) ====
==== inferTypePredicates.ts (10 errors) ====
// https://github.com/microsoft/TypeScript/issues/16069
const numsOrNull = [1, 2, 3, 4, null];
@ -298,9 +296,6 @@ inferTypePredicates.ts(252,7): error TS2322: Type 'string | number | Date' is no
declare let snd: string | number | Date;
if (assertAndPredicate(snd)) {
let t: string = snd; // should error
~
!!! error TS2322: Type 'string | number | Date' is not assignable to type 'string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
}
function isNumberWithThis(this: Date, x: number | string) {

Просмотреть файл

@ -661,7 +661,7 @@ function guardsOneButNotOthers(a: string|number, b: string|number, c: string|num
// String escaping issue (please help!)
function dunderguard(__x: number | string) {
>dunderguard : (__x: number | string) => ___x is string
>dunderguard : (__x: number | string) => __x is string
>__x : string | number
return typeof __x === 'string';
@ -886,7 +886,7 @@ if (isNumOrStr(unk)) {
// A function can be a type predicate even if it throws.
function assertAndPredicate(x: string | number | Date) {
>assertAndPredicate : (x: string | number | Date) => boolean
>assertAndPredicate : (x: string | number | Date) => x is string
>x : string | number | Date
if (x instanceof Date) {
@ -910,12 +910,12 @@ declare let snd: string | number | Date;
if (assertAndPredicate(snd)) {
>assertAndPredicate(snd) : boolean
>assertAndPredicate : (x: string | number | Date) => boolean
>assertAndPredicate : (x: string | number | Date) => x is string
>snd : string | number | Date
let t: string = snd; // should error
>t : string
>snd : string | number | Date
>snd : string
}
function isNumberWithThis(this: Date, x: number | string) {