diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e43001ec43..c25ec01fbf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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)); diff --git a/tests/baselines/reference/weakType.errors.txt b/tests/baselines/reference/weakType.errors.txt index 8d0da84859..432f3dfd8e 100644 --- a/tests/baselines/reference/weakType.errors.txt +++ b/tests/baselines/reference/weakType.errors.txt @@ -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; }'. \ No newline at end of file diff --git a/tests/baselines/reference/weakType.js b/tests/baselines/reference/weakType.js index 365b45d68c..6ed3ff1814 100644 --- a/tests/baselines/reference/weakType.js +++ b/tests/baselines/reference/weakType.js @@ -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; diff --git a/tests/cases/compiler/weakType.ts b/tests/cases/compiler/weakType.ts index a1d1cae7f6..f04f36c9c2 100644 --- a/tests/cases/compiler/weakType.ts +++ b/tests/cases/compiler/weakType.ts @@ -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