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:
parent
548f92ad34
commit
f9a05a1f9d
|
@ -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));
|
||||
|
|
|
@ -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; }'.
|
||||
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue