This commit is contained in:
Anders Hejlsberg 2024-07-24 14:48:03 -07:00
Родитель c706f5b9af
Коммит d27548c3d1
4 изменённых файлов: 49 добавлений и 55 удалений

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

@ -5,12 +5,10 @@ controlFlowGenericTypes.ts(81,11): error TS2339: Property 'foo' does not exist o
controlFlowGenericTypes.ts(90,44): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
controlFlowGenericTypes.ts(91,11): error TS2339: Property 'foo' does not exist on type 'MyUnion'.
Property 'foo' does not exist on type 'AA'.
controlFlowGenericTypes.ts(156,16): error TS18048: 'obj' is possibly 'undefined'.
controlFlowGenericTypes.ts(167,9): error TS18048: 'iSpec' is possibly 'undefined'.
controlFlowGenericTypes.ts(168,9): error TS18048: 'iSpec' is possibly 'undefined'.
controlFlowGenericTypes.ts(168,9): error TS2536: Type 'keyof PublicSpec' cannot be used to index type 'InternalSpec'.
==== controlFlowGenericTypes.ts (8 errors) ====
==== controlFlowGenericTypes.ts (6 errors) ====
function f1<T extends string | undefined>(x: T, y: { a: T }, z: [T]): string {
if (x) {
x;
@ -178,9 +176,7 @@ controlFlowGenericTypes.ts(168,9): error TS18048: 'iSpec' is possibly 'undefined
}
function fx3<T extends Record<keyof T, string> | undefined, K extends keyof T>(obj: T, key: K) {
const x1 = obj[key]; // Error
~~~
!!! error TS18048: 'obj' is possibly 'undefined'.
const x1 = obj[key];
const x2 = obj && obj[key];
}
@ -191,12 +187,10 @@ controlFlowGenericTypes.ts(168,9): error TS18048: 'iSpec' is possibly 'undefined
InternalSpec extends Record<keyof PublicSpec, any> | undefined = undefined> {
m() {
let iSpec = null! as InternalSpec;
iSpec[null! as keyof InternalSpec]; // Error, object possibly undefined
~~~~~
!!! error TS18048: 'iSpec' is possibly 'undefined'.
iSpec[null! as keyof PublicSpec]; // Error, object possibly undefined
~~~~~
!!! error TS18048: 'iSpec' is possibly 'undefined'.
iSpec[null! as keyof InternalSpec];
iSpec[null! as keyof PublicSpec]; // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2536: Type 'keyof PublicSpec' cannot be used to index type 'InternalSpec'.
if (iSpec === undefined) {
return;
}

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

@ -156,7 +156,7 @@ function fx2<T extends Record<keyof T, string>, K extends keyof T>(obj: T, key:
}
function fx3<T extends Record<keyof T, string> | undefined, K extends keyof T>(obj: T, key: K) {
const x1 = obj[key]; // Error
const x1 = obj[key];
const x2 = obj && obj[key];
}
@ -167,8 +167,8 @@ class TableBaseEnum<
InternalSpec extends Record<keyof PublicSpec, any> | undefined = undefined> {
m() {
let iSpec = null! as InternalSpec;
iSpec[null! as keyof InternalSpec]; // Error, object possibly undefined
iSpec[null! as keyof PublicSpec]; // Error, object possibly undefined
iSpec[null! as keyof InternalSpec];
iSpec[null! as keyof PublicSpec]; // Error
if (iSpec === undefined) {
return;
}
@ -339,7 +339,7 @@ function fx2(obj, key) {
var x2 = obj && obj[key];
}
function fx3(obj, key) {
var x1 = obj[key]; // Error
var x1 = obj[key];
var x2 = obj && obj[key];
}
// Repro from #44166
@ -348,8 +348,8 @@ var TableBaseEnum = /** @class */ (function () {
}
TableBaseEnum.prototype.m = function () {
var iSpec = null;
iSpec[null]; // Error, object possibly undefined
iSpec[null]; // Error, object possibly undefined
iSpec[null];
iSpec[null]; // Error
if (iSpec === undefined) {
return;
}

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

@ -469,7 +469,7 @@ function fx3<T extends Record<keyof T, string> | undefined, K extends keyof T>(o
>key : Symbol(key, Decl(controlFlowGenericTypes.ts, 154, 86))
>K : Symbol(K, Decl(controlFlowGenericTypes.ts, 154, 59))
const x1 = obj[key]; // Error
const x1 = obj[key];
>x1 : Symbol(x1, Decl(controlFlowGenericTypes.ts, 155, 9))
>obj : Symbol(obj, Decl(controlFlowGenericTypes.ts, 154, 79))
>key : Symbol(key, Decl(controlFlowGenericTypes.ts, 154, 86))
@ -503,11 +503,11 @@ class TableBaseEnum<
>iSpec : Symbol(iSpec, Decl(controlFlowGenericTypes.ts, 165, 11))
>InternalSpec : Symbol(InternalSpec, Decl(controlFlowGenericTypes.ts, 162, 55))
iSpec[null! as keyof InternalSpec]; // Error, object possibly undefined
iSpec[null! as keyof InternalSpec];
>iSpec : Symbol(iSpec, Decl(controlFlowGenericTypes.ts, 165, 11))
>InternalSpec : Symbol(InternalSpec, Decl(controlFlowGenericTypes.ts, 162, 55))
iSpec[null! as keyof PublicSpec]; // Error, object possibly undefined
iSpec[null! as keyof PublicSpec]; // Error
>iSpec : Symbol(iSpec, Decl(controlFlowGenericTypes.ts, 165, 11))
>PublicSpec : Symbol(PublicSpec, Decl(controlFlowGenericTypes.ts, 161, 20))

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

@ -661,27 +661,27 @@ function fx3<T extends Record<keyof T, string> | undefined, K extends keyof T>(o
>key : K
> : ^
const x1 = obj[key]; // Error
>x1 : Record<keyof T, string>[K]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
>obj[key] : Record<keyof T, string>[K]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
>obj : Record<keyof T, string> | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
const x1 = obj[key];
>x1 : T[K]
> : ^^^^
>obj[key] : T[K]
> : ^^^^
>obj : T
> : ^
>key : K
> : ^
const x2 = obj && obj[key];
>x2 : Record<keyof T, string>[K]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
>obj && obj[key] : Record<keyof T, string>[K]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
>x2 : NonNullable<T>[K]
> : ^^^^^^^^^^^^^^^^^
>obj && obj[key] : NonNullable<T>[K]
> : ^^^^^^^^^^^^^^^^^
>obj : T
> : ^
>obj[key] : Record<keyof T, string>[K]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
>obj : Record<keyof T, string>
> : ^^^^^^^^^^^^^^^^^^^^^^^
>obj[key] : NonNullable<T>[K]
> : ^^^^^^^^^^^^^^^^^
>obj : NonNullable<T>
> : ^^^^^^^^^^^^^^
>key : K
> : ^
}
@ -706,21 +706,21 @@ class TableBaseEnum<
>null! : never
> : ^^^^^
iSpec[null! as keyof InternalSpec]; // Error, object possibly undefined
>iSpec[null! as keyof InternalSpec] : Record<keyof PublicSpec, any>[keyof InternalSpec]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>iSpec : Record<keyof PublicSpec, any> | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
iSpec[null! as keyof InternalSpec];
>iSpec[null! as keyof InternalSpec] : InternalSpec[keyof InternalSpec]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>iSpec : InternalSpec
> : ^^^^^^^^^^^^
>null! as keyof InternalSpec : keyof InternalSpec
> : ^^^^^^^^^^^^^^^^^^
>null! : never
> : ^^^^^
iSpec[null! as keyof PublicSpec]; // Error, object possibly undefined
>iSpec[null! as keyof PublicSpec] : Record<keyof PublicSpec, any>[keyof PublicSpec]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>iSpec : Record<keyof PublicSpec, any> | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
iSpec[null! as keyof PublicSpec]; // Error
>iSpec[null! as keyof PublicSpec] : any
> : ^^^
>iSpec : InternalSpec
> : ^^^^^^^^^^^^
>null! as keyof PublicSpec : keyof PublicSpec
> : ^^^^^^^^^^^^^^^^
>null! : never
@ -737,20 +737,20 @@ class TableBaseEnum<
return;
}
iSpec[null! as keyof InternalSpec];
>iSpec[null! as keyof InternalSpec] : Record<keyof PublicSpec, any>[keyof InternalSpec]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>iSpec : Record<keyof PublicSpec, any>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>iSpec[null! as keyof InternalSpec] : (InternalSpec & {})[keyof InternalSpec]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>iSpec : InternalSpec & {}
> : ^^^^^^^^^^^^^^^^^
>null! as keyof InternalSpec : keyof InternalSpec
> : ^^^^^^^^^^^^^^^^^^
>null! : never
> : ^^^^^
iSpec[null! as keyof PublicSpec];
>iSpec[null! as keyof PublicSpec] : Record<keyof PublicSpec, any>[keyof PublicSpec]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>iSpec : Record<keyof PublicSpec, any>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>iSpec[null! as keyof PublicSpec] : (InternalSpec & {})[keyof PublicSpec]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>iSpec : InternalSpec & {}
> : ^^^^^^^^^^^^^^^^^
>null! as keyof PublicSpec : keyof PublicSpec
> : ^^^^^^^^^^^^^^^^
>null! : never