TypeScript/tests/baselines/reference/intersectionsAndOptionalProperties.errors.txt

54 lines
2.5 KiB
Plaintext

tests/cases/compiler/intersectionsAndOptionalProperties.ts(5,1): error TS2322: Type '{ a: null; b: string; }' is not assignable to type '{ a?: number | undefined; b: string; }'.
Types of property 'a' are incompatible.
Type 'null' is not assignable to type 'number | undefined'.
tests/cases/compiler/intersectionsAndOptionalProperties.ts(6,1): error TS2322: Type '{ a: null; } & { b: string; }' is not assignable to type '{ a?: number | undefined; b: string; }'.
Types of property 'a' are incompatible.
Type 'null' is not assignable to type 'number | undefined'.
tests/cases/compiler/intersectionsAndOptionalProperties.ts(19,5): error TS2322: Type 'From' is not assignable to type 'To'.
Types of property 'field' are incompatible.
Type 'null' is not assignable to type 'number | undefined'.
tests/cases/compiler/intersectionsAndOptionalProperties.ts(20,5): error TS2322: Type 'null' is not assignable to type 'number | undefined'.
==== tests/cases/compiler/intersectionsAndOptionalProperties.ts (4 errors) ====
declare let x: { a?: number, b: string };
declare let y: { a: null, b: string };
declare let z: { a: null } & { b: string };
x = y; // Error
~
!!! error TS2322: Type '{ a: null; b: string; }' is not assignable to type '{ a?: number | undefined; b: string; }'.
!!! error TS2322: Types of property 'a' are incompatible.
!!! error TS2322: Type 'null' is not assignable to type 'number | undefined'.
x = z; // Error
~
!!! error TS2322: Type '{ a: null; } & { b: string; }' is not assignable to type '{ a?: number | undefined; b: string; }'.
!!! error TS2322: Types of property 'a' are incompatible.
!!! error TS2322: Type 'null' is not assignable to type 'number | undefined'.
// Repro from #36604
interface To {
field?: number;
anotherField: string;
}
type From = { field: null } & Omit<To, 'field'>;
function foo(v: From) {
let x: To;
x = v; // Error
~
!!! error TS2322: Type 'From' is not assignable to type 'To'.
!!! error TS2322: Types of property 'field' are incompatible.
!!! error TS2322: Type 'null' is not assignable to type 'number | undefined'.
x.field = v.field; // Error
~~~~~~~
!!! error TS2322: Type 'null' is not assignable to type 'number | undefined'.
}
// Repro from #38348
const yy: number[] & [number, ...number[]] = [1];
const xx: [number, ...number[]] = yy;