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
4 changed files with 58 additions and 1 deletions
|
@ -9352,7 +9352,10 @@ namespace ts {
|
||||||
}
|
}
|
||||||
return Ternary.False;
|
return Ternary.False;
|
||||||
}
|
}
|
||||||
|
const saveDisableWeakTypeErrors = disableWeakTypeErrors;
|
||||||
|
disableWeakTypeErrors = false;
|
||||||
const related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
|
const related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
|
||||||
|
disableWeakTypeErrors = saveDisableWeakTypeErrors;
|
||||||
if (!related) {
|
if (!related) {
|
||||||
if (reportErrors) {
|
if (reportErrors) {
|
||||||
reportError(Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp));
|
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'.
|
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; }'.
|
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 {
|
interface Settings {
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
onError?(): void;
|
onError?(): void;
|
||||||
|
@ -49,3 +54,23 @@ tests/cases/compiler/weakType.ts(31,18): error TS2345: Argument of type '{ error
|
||||||
}
|
}
|
||||||
let ctor: Ctor = K
|
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; }'.
|
||||||
|
|
|
@ -42,6 +42,20 @@ interface Ctor {
|
||||||
}
|
}
|
||||||
let ctor: Ctor = K
|
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]
|
//// [weakType.js]
|
||||||
function getDefaultSettings() {
|
function getDefaultSettings() {
|
||||||
|
@ -64,3 +78,4 @@ var K = (function () {
|
||||||
return K;
|
return K;
|
||||||
}());
|
}());
|
||||||
var ctor = K;
|
var ctor = K;
|
||||||
|
var weak = unknown;
|
||||||
|
|
|
@ -40,3 +40,17 @@ interface Ctor {
|
||||||
n?: number
|
n?: number
|
||||||
}
|
}
|
||||||
let ctor: Ctor = K
|
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