Re-enable weak type check for intersection props

Previously, intersections disabled the weak type check for their
constituents, and all properties (recursively) of their constituents.

Also add test for this case.
This commit is contained in:
Nathan Shively-Sanders 2017-05-26 13:39:53 -07:00
parent 548f92ad34
commit f9a05a1f9d
4 changed files with 58 additions and 1 deletions

View file

@ -9352,7 +9352,10 @@ namespace ts {
}
return Ternary.False;
}
const saveDisableWeakTypeErrors = disableWeakTypeErrors;
disableWeakTypeErrors = false;
const related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
disableWeakTypeErrors = saveDisableWeakTypeErrors;
if (!related) {
if (reportErrors) {
reportError(Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp));

View file

@ -1,8 +1,13 @@
tests/cases/compiler/weakType.ts(31,18): error TS2345: Argument of type '{ error?: number; }' is not assignable to parameter of type 'ChangeOptions'.
Weak type 'ChangeOptions' has no properties in common with '{ error?: number; }'.
tests/cases/compiler/weakType.ts(56,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; }' is not assignable to type '{ b?: number; }'.
Weak type '{ b?: number; }' has no properties in common with '{ wrong: string; }'.
==== tests/cases/compiler/weakType.ts (1 errors) ====
==== tests/cases/compiler/weakType.ts (2 errors) ====
interface Settings {
timeout?: number;
onError?(): void;
@ -48,4 +53,24 @@ tests/cases/compiler/weakType.ts(31,18): error TS2345: Argument of type '{ error
n?: number
}
let ctor: Ctor = K
type Spoiler = { nope?: string }
type Weak = {
a?: number
properties?: {
b?: number
}
}
declare let unknown: {
properties: {
wrong: string
}
}
let weak: Weak & Spoiler = unknown
~~~~
!!! error TS2322: Type '{ properties: { wrong: string; }; }' is not assignable to type 'Weak & Spoiler'.
!!! error TS2322: Type '{ properties: { wrong: string; }; }' is not assignable to type 'Weak'.
!!! error TS2322: Types of property 'properties' are incompatible.
!!! error TS2322: Type '{ wrong: string; }' is not assignable to type '{ b?: number; }'.
!!! error TS2322: Weak type '{ b?: number; }' has no properties in common with '{ wrong: string; }'.

View file

@ -41,6 +41,20 @@ interface Ctor {
n?: number
}
let ctor: Ctor = K
type Spoiler = { nope?: string }
type Weak = {
a?: number
properties?: {
b?: number
}
}
declare let unknown: {
properties: {
wrong: string
}
}
let weak: Weak & Spoiler = unknown
//// [weakType.js]
@ -64,3 +78,4 @@ var K = (function () {
return K;
}());
var ctor = K;
var weak = unknown;

View file

@ -40,3 +40,17 @@ interface Ctor {
n?: number
}
let ctor: Ctor = K
type Spoiler = { nope?: string }
type Weak = {
a?: number
properties?: {
b?: number
}
}
declare let unknown: {
properties: {
wrong: string
}
}
let weak: Weak & Spoiler = unknown