Skip to content

Commit 67014b0

Browse files
committed
Add noLib test
1 parent 060f0b2 commit 67014b0

5 files changed

+339
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error TS2318: Cannot find global type 'Array'.
2+
error TS2318: Cannot find global type 'Boolean'.
3+
error TS2318: Cannot find global type 'Function'.
4+
error TS2318: Cannot find global type 'IArguments'.
5+
error TS2318: Cannot find global type 'Number'.
6+
error TS2318: Cannot find global type 'Object'.
7+
error TS2318: Cannot find global type 'RegExp'.
8+
error TS2318: Cannot find global type 'String'.
9+
10+
11+
!!! error TS2318: Cannot find global type 'Array'.
12+
!!! error TS2318: Cannot find global type 'Boolean'.
13+
!!! error TS2318: Cannot find global type 'Function'.
14+
!!! error TS2318: Cannot find global type 'IArguments'.
15+
!!! error TS2318: Cannot find global type 'Number'.
16+
!!! error TS2318: Cannot find global type 'Object'.
17+
!!! error TS2318: Cannot find global type 'RegExp'.
18+
!!! error TS2318: Cannot find global type 'String'.
19+
==== tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts (0 errors) ====
20+
type Readonly<T> = {readonly [K in keyof T]: T[K]}
21+
interface A {
22+
params?: { name: string; };
23+
}
24+
25+
class Test<T extends A> {
26+
attrs: Readonly<T>;
27+
28+
m() {
29+
this.attrs.params!.name;
30+
}
31+
}
32+
33+
interface Foo {
34+
foo?: number;
35+
}
36+
37+
class FooClass<P extends Foo = Foo> {
38+
properties: Readonly<P>;
39+
40+
foo(): number {
41+
const { foo = 42 } = this.properties;
42+
return foo;
43+
}
44+
}
45+
46+
class Test2<T extends A> {
47+
attrs: Readonly<T>;
48+
49+
m() {
50+
return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//// [strictNullNotNullIndexTypeNoLib.ts]
2+
type Readonly<T> = {readonly [K in keyof T]: T[K]}
3+
interface A {
4+
params?: { name: string; };
5+
}
6+
7+
class Test<T extends A> {
8+
attrs: Readonly<T>;
9+
10+
m() {
11+
this.attrs.params!.name;
12+
}
13+
}
14+
15+
interface Foo {
16+
foo?: number;
17+
}
18+
19+
class FooClass<P extends Foo = Foo> {
20+
properties: Readonly<P>;
21+
22+
foo(): number {
23+
const { foo = 42 } = this.properties;
24+
return foo;
25+
}
26+
}
27+
28+
class Test2<T extends A> {
29+
attrs: Readonly<T>;
30+
31+
m() {
32+
return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally
33+
}
34+
}
35+
36+
//// [strictNullNotNullIndexTypeNoLib.js]
37+
var Test = /** @class */ (function () {
38+
function Test() {
39+
}
40+
Test.prototype.m = function () {
41+
this.attrs.params.name;
42+
};
43+
return Test;
44+
}());
45+
var FooClass = /** @class */ (function () {
46+
function FooClass() {
47+
}
48+
FooClass.prototype.foo = function () {
49+
var _a = this.properties.foo, foo = _a === void 0 ? 42 : _a;
50+
return foo;
51+
};
52+
return FooClass;
53+
}());
54+
var Test2 = /** @class */ (function () {
55+
function Test2() {
56+
}
57+
Test2.prototype.m = function () {
58+
return this.attrs.params; // Return type should maintain relationship with `T` after being not-null-asserted, ideally
59+
};
60+
return Test2;
61+
}());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
=== tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts ===
2+
type Readonly<T> = {readonly [K in keyof T]: T[K]}
3+
>Readonly : Symbol(Readonly, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 0))
4+
>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 14))
5+
>K : Symbol(K, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 30))
6+
>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 14))
7+
>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 14))
8+
>K : Symbol(K, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 30))
9+
10+
interface A {
11+
>A : Symbol(A, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 50))
12+
13+
params?: { name: string; };
14+
>params : Symbol(A.params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13))
15+
>name : Symbol(name, Decl(strictNullNotNullIndexTypeNoLib.ts, 2, 14))
16+
}
17+
18+
class Test<T extends A> {
19+
>Test : Symbol(Test, Decl(strictNullNotNullIndexTypeNoLib.ts, 3, 1))
20+
>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 11))
21+
>A : Symbol(A, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 50))
22+
23+
attrs: Readonly<T>;
24+
>attrs : Symbol(Test.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 25))
25+
>Readonly : Symbol(Readonly, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 0))
26+
>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 11))
27+
28+
m() {
29+
>m : Symbol(Test.m, Decl(strictNullNotNullIndexTypeNoLib.ts, 6, 23))
30+
31+
this.attrs.params!.name;
32+
>this.attrs.params!.name : Symbol(name, Decl(strictNullNotNullIndexTypeNoLib.ts, 2, 14))
33+
>this.attrs.params : Symbol(params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13))
34+
>this.attrs : Symbol(Test.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 25))
35+
>this : Symbol(Test, Decl(strictNullNotNullIndexTypeNoLib.ts, 3, 1))
36+
>attrs : Symbol(Test.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 5, 25))
37+
>params : Symbol(params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13))
38+
>name : Symbol(name, Decl(strictNullNotNullIndexTypeNoLib.ts, 2, 14))
39+
}
40+
}
41+
42+
interface Foo {
43+
>Foo : Symbol(Foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 11, 1))
44+
45+
foo?: number;
46+
>foo : Symbol(Foo.foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 13, 15))
47+
}
48+
49+
class FooClass<P extends Foo = Foo> {
50+
>FooClass : Symbol(FooClass, Decl(strictNullNotNullIndexTypeNoLib.ts, 15, 1))
51+
>P : Symbol(P, Decl(strictNullNotNullIndexTypeNoLib.ts, 17, 15))
52+
>Foo : Symbol(Foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 11, 1))
53+
>Foo : Symbol(Foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 11, 1))
54+
55+
properties: Readonly<P>;
56+
>properties : Symbol(FooClass.properties, Decl(strictNullNotNullIndexTypeNoLib.ts, 17, 37))
57+
>Readonly : Symbol(Readonly, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 0))
58+
>P : Symbol(P, Decl(strictNullNotNullIndexTypeNoLib.ts, 17, 15))
59+
60+
foo(): number {
61+
>foo : Symbol(FooClass.foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 18, 28))
62+
63+
const { foo = 42 } = this.properties;
64+
>foo : Symbol(foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 21, 15))
65+
>this.properties : Symbol(FooClass.properties, Decl(strictNullNotNullIndexTypeNoLib.ts, 17, 37))
66+
>this : Symbol(FooClass, Decl(strictNullNotNullIndexTypeNoLib.ts, 15, 1))
67+
>properties : Symbol(FooClass.properties, Decl(strictNullNotNullIndexTypeNoLib.ts, 17, 37))
68+
69+
return foo;
70+
>foo : Symbol(foo, Decl(strictNullNotNullIndexTypeNoLib.ts, 21, 15))
71+
}
72+
}
73+
74+
class Test2<T extends A> {
75+
>Test2 : Symbol(Test2, Decl(strictNullNotNullIndexTypeNoLib.ts, 24, 1))
76+
>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 26, 12))
77+
>A : Symbol(A, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 50))
78+
79+
attrs: Readonly<T>;
80+
>attrs : Symbol(Test2.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 26, 26))
81+
>Readonly : Symbol(Readonly, Decl(strictNullNotNullIndexTypeNoLib.ts, 0, 0))
82+
>T : Symbol(T, Decl(strictNullNotNullIndexTypeNoLib.ts, 26, 12))
83+
84+
m() {
85+
>m : Symbol(Test2.m, Decl(strictNullNotNullIndexTypeNoLib.ts, 27, 23))
86+
87+
return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally
88+
>this.attrs.params : Symbol(params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13))
89+
>this.attrs : Symbol(Test2.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 26, 26))
90+
>this : Symbol(Test2, Decl(strictNullNotNullIndexTypeNoLib.ts, 24, 1))
91+
>attrs : Symbol(Test2.attrs, Decl(strictNullNotNullIndexTypeNoLib.ts, 26, 26))
92+
>params : Symbol(params, Decl(strictNullNotNullIndexTypeNoLib.ts, 1, 13))
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
=== tests/cases/compiler/strictNullNotNullIndexTypeNoLib.ts ===
2+
type Readonly<T> = {readonly [K in keyof T]: T[K]}
3+
>Readonly : Readonly<T>
4+
>T : T
5+
>K : K
6+
>T : T
7+
>T : T
8+
>K : K
9+
10+
interface A {
11+
>A : A
12+
13+
params?: { name: string; };
14+
>params : { name: string; } | undefined
15+
>name : string
16+
}
17+
18+
class Test<T extends A> {
19+
>Test : Test<T>
20+
>T : T
21+
>A : A
22+
23+
attrs: Readonly<T>;
24+
>attrs : Readonly<T>
25+
>Readonly : Readonly<T>
26+
>T : T
27+
28+
m() {
29+
>m : () => void
30+
31+
this.attrs.params!.name;
32+
>this.attrs.params!.name : string
33+
>this.attrs.params! : T["params"] extends null | undefined ? never : T["params"]
34+
>this.attrs.params : T["params"]
35+
>this.attrs : Readonly<T>
36+
>this : this
37+
>attrs : Readonly<T>
38+
>params : T["params"]
39+
>name : string
40+
}
41+
}
42+
43+
interface Foo {
44+
>Foo : Foo
45+
46+
foo?: number;
47+
>foo : number | undefined
48+
}
49+
50+
class FooClass<P extends Foo = Foo> {
51+
>FooClass : FooClass<P>
52+
>P : P
53+
>Foo : Foo
54+
>Foo : Foo
55+
56+
properties: Readonly<P>;
57+
>properties : Readonly<P>
58+
>Readonly : Readonly<T>
59+
>P : P
60+
61+
foo(): number {
62+
>foo : () => number
63+
64+
const { foo = 42 } = this.properties;
65+
>foo : number
66+
>42 : 42
67+
>this.properties : Readonly<P>
68+
>this : this
69+
>properties : Readonly<P>
70+
71+
return foo;
72+
>foo : number
73+
}
74+
}
75+
76+
class Test2<T extends A> {
77+
>Test2 : Test2<T>
78+
>T : T
79+
>A : A
80+
81+
attrs: Readonly<T>;
82+
>attrs : Readonly<T>
83+
>Readonly : Readonly<T>
84+
>T : T
85+
86+
m() {
87+
>m : () => T["params"] extends null | undefined ? never : T["params"]
88+
89+
return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally
90+
>this.attrs.params! : T["params"] extends null | undefined ? never : T["params"]
91+
>this.attrs.params : T["params"]
92+
>this.attrs : Readonly<T>
93+
>this : this
94+
>attrs : Readonly<T>
95+
>params : T["params"]
96+
}
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// @strictNullChecks: true
2+
// @noLib: true
3+
type Readonly<T> = {readonly [K in keyof T]: T[K]}
4+
interface A {
5+
params?: { name: string; };
6+
}
7+
8+
class Test<T extends A> {
9+
attrs: Readonly<T>;
10+
11+
m() {
12+
this.attrs.params!.name;
13+
}
14+
}
15+
16+
interface Foo {
17+
foo?: number;
18+
}
19+
20+
class FooClass<P extends Foo = Foo> {
21+
properties: Readonly<P>;
22+
23+
foo(): number {
24+
const { foo = 42 } = this.properties;
25+
return foo;
26+
}
27+
}
28+
29+
class Test2<T extends A> {
30+
attrs: Readonly<T>;
31+
32+
m() {
33+
return this.attrs.params!; // Return type should maintain relationship with `T` after being not-null-asserted, ideally
34+
}
35+
}

0 commit comments

Comments
 (0)