From b509e681c1d2580c3c73093cbee1fd0a6db4853c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 7 Jun 2017 16:20:58 -0700 Subject: [PATCH] Test weak type errors with primitives --- .../reference/generatorTypeCheck63.errors.txt | 26 ++++++++++--------- tests/baselines/reference/weakType.errors.txt | 21 ++++++++++++--- tests/baselines/reference/weakType.js | 11 +++++++- tests/cases/compiler/weakType.ts | 6 ++++- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/generatorTypeCheck63.errors.txt b/tests/baselines/reference/generatorTypeCheck63.errors.txt index ed2ed36a438..c08635e8b73 100644 --- a/tests/baselines/reference/generatorTypeCheck63.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck63.errors.txt @@ -1,11 +1,12 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,14): error TS2322: Type '(a: State | 1) => IterableIterator' is not assignable to type 'Strategy'. - Type 'IterableIterator' is not assignable to type 'IterableIterator'. - Type 'State | 1' is not assignable to type 'State'. - Type '1' is not assignable to type 'State'. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,61): error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: StrategicState) => IterableIterator'. + Type 'IterableIterator' is not assignable to type 'IterableIterator'. + Type 'State | 1' is not assignable to type 'StrategicState'. + Type '1' has no properties in common with type 'StrategicState'. tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(29,70): error TS7025: Generator implicitly has type 'IterableIterator' because it does not yield any values. Consider supplying a return type. 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. Type argument candidate 'State' is not a valid type argument because it is not a supertype of candidate '1'. -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): error TS2322: Type '(a: State | 1) => IterableIterator' is not assignable to type 'Strategy'. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,62): error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: StrategicState) => IterableIterator'. + Type 'IterableIterator' is not assignable to type 'IterableIterator'. ==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts (4 errors) ==== @@ -33,11 +34,11 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): err } export const Nothing: Strategy = strategy("Nothing", function* (state: State) { - ~~~~~~~ -!!! error TS2322: Type '(a: State | 1) => IterableIterator' is not assignable to type 'Strategy'. -!!! error TS2322: Type 'IterableIterator' is not assignable to type 'IterableIterator'. -!!! error TS2322: Type 'State | 1' is not assignable to type 'State'. -!!! error TS2322: Type '1' is not assignable to type 'State'. + ~~~~~~~~ +!!! error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: StrategicState) => IterableIterator'. +!!! error TS2345: Type 'IterableIterator' is not assignable to type 'IterableIterator'. +!!! error TS2345: Type 'State | 1' is not assignable to type 'StrategicState'. +!!! error TS2345: Type '1' has no properties in common with type 'StrategicState'. yield 1; return state; }); @@ -55,8 +56,9 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): err }); export const Nothing3: Strategy = strategy("Nothing", function* (state: State) { - ~~~~~~~~ -!!! error TS2322: Type '(a: State | 1) => IterableIterator' is not assignable to type 'Strategy'. + ~~~~~~~~ +!!! error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: StrategicState) => IterableIterator'. +!!! error TS2345: Type 'IterableIterator' is not assignable to type 'IterableIterator'. yield state; return 1; }); \ No newline at end of file diff --git a/tests/baselines/reference/weakType.errors.txt b/tests/baselines/reference/weakType.errors.txt index 7064ace5daa..441ef70ac16 100644 --- a/tests/baselines/reference/weakType.errors.txt +++ b/tests/baselines/reference/weakType.errors.txt @@ -1,11 +1,14 @@ -tests/cases/compiler/weakType.ts(31,18): error TS2559: Type '{ error?: number; }' has no properties in common with type 'ChangeOptions'. -tests/cases/compiler/weakType.ts(56,5): error TS2322: Type '{ properties: { wrong: string; }; }' is not assignable to type 'Weak & Spoiler'. +tests/cases/compiler/weakType.ts(16,13): error TS2559: Type '12' has no properties in common with type 'Settings'. +tests/cases/compiler/weakType.ts(17,13): error TS2559: Type '"completely wrong"' has no properties in common with type 'Settings'. +tests/cases/compiler/weakType.ts(18,13): error TS2559: Type 'false' has no properties in common with type 'Settings'. +tests/cases/compiler/weakType.ts(35,18): error TS2559: Type '{ error?: number; }' has no properties in common with type 'ChangeOptions'. +tests/cases/compiler/weakType.ts(60,5): error TS2322: Type '{ properties: { wrong: string; }; }' is not assignable to type 'Weak & Spoiler'. Type '{ properties: { wrong: string; }; }' is not assignable to type 'Weak'. Types of property 'properties' are incompatible. Type '{ wrong: string; }' has no properties in common with type '{ b?: number; }'. -==== tests/cases/compiler/weakType.ts (2 errors) ==== +==== tests/cases/compiler/weakType.ts (5 errors) ==== interface Settings { timeout?: number; onError?(): void; @@ -16,10 +19,20 @@ tests/cases/compiler/weakType.ts(56,5): error TS2322: Type '{ properties: { wron } function doSomething(settings: Settings) { /* ... */ } - // forgot to call `getDefaultSettings` // but it is not caught because we don't check for call signatures doSomething(getDefaultSettings); + // same for arrow expressions: + doSomething(() => { }); + doSomething(12); + ~~ +!!! error TS2559: Type '12' has no properties in common with type 'Settings'. + doSomething('completely wrong'); + ~~~~~~~~~~~~~~~~~~ +!!! error TS2559: Type '"completely wrong"' has no properties in common with type 'Settings'. + doSomething(false); + ~~~~~ +!!! error TS2559: Type 'false' has no properties in common with type 'Settings'. // this is an oddly popular way of defining settings // this example is from services/textChanges.ts diff --git a/tests/baselines/reference/weakType.js b/tests/baselines/reference/weakType.js index 6ed3ff1814d..5637271ccec 100644 --- a/tests/baselines/reference/weakType.js +++ b/tests/baselines/reference/weakType.js @@ -9,10 +9,14 @@ function getDefaultSettings() { } function doSomething(settings: Settings) { /* ... */ } - // forgot to call `getDefaultSettings` // but it is not caught because we don't check for call signatures doSomething(getDefaultSettings); +// same for arrow expressions: +doSomething(() => { }); +doSomething(12); +doSomething('completely wrong'); +doSomething(false); // this is an oddly popular way of defining settings // this example is from services/textChanges.ts @@ -65,6 +69,11 @@ function doSomething(settings) { } // forgot to call `getDefaultSettings` // but it is not caught because we don't check for call signatures doSomething(getDefaultSettings); +// same for arrow expressions: +doSomething(function () { }); +doSomething(12); +doSomething('completely wrong'); +doSomething(false); function del(options, error) { if (options === void 0) { options = {}; } if (error === void 0) { error = {}; } diff --git a/tests/cases/compiler/weakType.ts b/tests/cases/compiler/weakType.ts index f04f36c9c2f..ffe51205e53 100644 --- a/tests/cases/compiler/weakType.ts +++ b/tests/cases/compiler/weakType.ts @@ -8,10 +8,14 @@ function getDefaultSettings() { } function doSomething(settings: Settings) { /* ... */ } - // forgot to call `getDefaultSettings` // but it is not caught because we don't check for call signatures doSomething(getDefaultSettings); +// same for arrow expressions: +doSomething(() => { }); +doSomething(12); +doSomething('completely wrong'); +doSomething(false); // this is an oddly popular way of defining settings // this example is from services/textChanges.ts