Skip to content

Required<T> optional properties type validation will not work #29991

Closed
@misuken-now

Description

@misuken-now

TypeScript Version: 3.2.0-rc <= 3.4.0-dev.20190220

Search Terms: Required

Code

const a: Required<{ a?: 1; x: 1 }> = { a: 1, x: 1 };
const b: Required<{ b?: 1; x: 1 }> = { b: 1, x: 1 };
export let A = a;
export let B = b;
A = b; // No Error
B = a; // No Error

a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
b.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.

Expected behavior:

Error:(5, 1) TS2322: Type 'Required<{ b?: 1 | undefined; x: 1; }>' is not assignable to type 'Required<{ a?: 1 | undefined; x: 1; }>'.
  Property 'a' is missing in type 'Required<{ b?: 1 | undefined; x: 1; }>'.
Error:(6, 1) TS2322: Type 'Required<{ a?: 1 | undefined; x: 1; }>' is not assignable to type 'Required<{ b?: 1 | undefined; x: 1; }>'.
  Property 'b' is missing in type 'Required<{ a?: 1 | undefined; x: 1; }>'.

When it is "3.1.6" it will be like that.

Actual behavior:

No Error

Playground Link:

link

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions