Skip to content

Commit b509e68

Browse files
committed
Test weak type errors with primitives
1 parent efa490e commit b509e68

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

tests/baselines/reference/generatorTypeCheck63.errors.txt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,14): error TS2322: Type '(a: State | 1) => IterableIterator<State | 1>' is not assignable to type 'Strategy<State>'.
2-
Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<State>'.
3-
Type 'State | 1' is not assignable to type 'State'.
4-
Type '1' is not assignable to type 'State'.
1+
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,61): error TS2345: Argument of type '(state: State) => IterableIterator<State | 1>' is not assignable to parameter of type '(a: StrategicState) => IterableIterator<StrategicState>'.
2+
Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<StrategicState>'.
3+
Type 'State | 1' is not assignable to type 'StrategicState'.
4+
Type '1' has no properties in common with type 'StrategicState'.
55
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(29,70): error TS7025: Generator implicitly has type 'IterableIterator<any>' because it does not yield any values. Consider supplying a return type.
66
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(32,42): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
77
Type argument candidate 'State' is not a valid type argument because it is not a supertype of candidate '1'.
8-
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): error TS2322: Type '(a: State | 1) => IterableIterator<State | 1>' is not assignable to type 'Strategy<State>'.
8+
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,62): error TS2345: Argument of type '(state: State) => IterableIterator<State | 1>' is not assignable to parameter of type '(a: StrategicState) => IterableIterator<StrategicState>'.
9+
Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<StrategicState>'.
910

1011

1112
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts (4 errors) ====
@@ -33,11 +34,11 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): err
3334
}
3435

3536
export const Nothing: Strategy<State> = strategy("Nothing", function* (state: State) {
36-
~~~~~~~
37-
!!! error TS2322: Type '(a: State | 1) => IterableIterator<State | 1>' is not assignable to type 'Strategy<State>'.
38-
!!! error TS2322: Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<State>'.
39-
!!! error TS2322: Type 'State | 1' is not assignable to type 'State'.
40-
!!! error TS2322: Type '1' is not assignable to type 'State'.
37+
~~~~~~~~
38+
!!! error TS2345: Argument of type '(state: State) => IterableIterator<State | 1>' is not assignable to parameter of type '(a: StrategicState) => IterableIterator<StrategicState>'.
39+
!!! error TS2345: Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<StrategicState>'.
40+
!!! error TS2345: Type 'State | 1' is not assignable to type 'StrategicState'.
41+
!!! error TS2345: Type '1' has no properties in common with type 'StrategicState'.
4142
yield 1;
4243
return state;
4344
});
@@ -55,8 +56,9 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): err
5556
});
5657

5758
export const Nothing3: Strategy<State> = strategy("Nothing", function* (state: State) {
58-
~~~~~~~~
59-
!!! error TS2322: Type '(a: State | 1) => IterableIterator<State | 1>' is not assignable to type 'Strategy<State>'.
59+
~~~~~~~~
60+
!!! error TS2345: Argument of type '(state: State) => IterableIterator<State | 1>' is not assignable to parameter of type '(a: StrategicState) => IterableIterator<StrategicState>'.
61+
!!! error TS2345: Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<StrategicState>'.
6062
yield state;
6163
return 1;
6264
});

tests/baselines/reference/weakType.errors.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
tests/cases/compiler/weakType.ts(31,18): error TS2559: Type '{ error?: number; }' has no properties in common with type 'ChangeOptions'.
2-
tests/cases/compiler/weakType.ts(56,5): error TS2322: Type '{ properties: { wrong: string; }; }' is not assignable to type 'Weak & Spoiler'.
1+
tests/cases/compiler/weakType.ts(16,13): error TS2559: Type '12' has no properties in common with type 'Settings'.
2+
tests/cases/compiler/weakType.ts(17,13): error TS2559: Type '"completely wrong"' has no properties in common with type 'Settings'.
3+
tests/cases/compiler/weakType.ts(18,13): error TS2559: Type 'false' has no properties in common with type 'Settings'.
4+
tests/cases/compiler/weakType.ts(35,18): error TS2559: Type '{ error?: number; }' has no properties in common with type 'ChangeOptions'.
5+
tests/cases/compiler/weakType.ts(60,5): error TS2322: Type '{ properties: { wrong: string; }; }' is not assignable to type 'Weak & Spoiler'.
36
Type '{ properties: { wrong: string; }; }' is not assignable to type 'Weak'.
47
Types of property 'properties' are incompatible.
58
Type '{ wrong: string; }' has no properties in common with type '{ b?: number; }'.
69

710

8-
==== tests/cases/compiler/weakType.ts (2 errors) ====
11+
==== tests/cases/compiler/weakType.ts (5 errors) ====
912
interface Settings {
1013
timeout?: number;
1114
onError?(): void;
@@ -16,10 +19,20 @@ tests/cases/compiler/weakType.ts(56,5): error TS2322: Type '{ properties: { wron
1619
}
1720

1821
function doSomething(settings: Settings) { /* ... */ }
19-
2022
// forgot to call `getDefaultSettings`
2123
// but it is not caught because we don't check for call signatures
2224
doSomething(getDefaultSettings);
25+
// same for arrow expressions:
26+
doSomething(() => { });
27+
doSomething(12);
28+
~~
29+
!!! error TS2559: Type '12' has no properties in common with type 'Settings'.
30+
doSomething('completely wrong');
31+
~~~~~~~~~~~~~~~~~~
32+
!!! error TS2559: Type '"completely wrong"' has no properties in common with type 'Settings'.
33+
doSomething(false);
34+
~~~~~
35+
!!! error TS2559: Type 'false' has no properties in common with type 'Settings'.
2336

2437
// this is an oddly popular way of defining settings
2538
// this example is from services/textChanges.ts

tests/baselines/reference/weakType.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ function getDefaultSettings() {
99
}
1010

1111
function doSomething(settings: Settings) { /* ... */ }
12-
1312
// forgot to call `getDefaultSettings`
1413
// but it is not caught because we don't check for call signatures
1514
doSomething(getDefaultSettings);
15+
// same for arrow expressions:
16+
doSomething(() => { });
17+
doSomething(12);
18+
doSomething('completely wrong');
19+
doSomething(false);
1620

1721
// this is an oddly popular way of defining settings
1822
// this example is from services/textChanges.ts
@@ -65,6 +69,11 @@ function doSomething(settings) { }
6569
// forgot to call `getDefaultSettings`
6670
// but it is not caught because we don't check for call signatures
6771
doSomething(getDefaultSettings);
72+
// same for arrow expressions:
73+
doSomething(function () { });
74+
doSomething(12);
75+
doSomething('completely wrong');
76+
doSomething(false);
6877
function del(options, error) {
6978
if (options === void 0) { options = {}; }
7079
if (error === void 0) { error = {}; }

tests/cases/compiler/weakType.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ function getDefaultSettings() {
88
}
99

1010
function doSomething(settings: Settings) { /* ... */ }
11-
1211
// forgot to call `getDefaultSettings`
1312
// but it is not caught because we don't check for call signatures
1413
doSomething(getDefaultSettings);
14+
// same for arrow expressions:
15+
doSomething(() => { });
16+
doSomething(12);
17+
doSomething('completely wrong');
18+
doSomething(false);
1519

1620
// this is an oddly popular way of defining settings
1721
// this example is from services/textChanges.ts

0 commit comments

Comments
 (0)