Skip to content

Incorrect error when assigning to omitted and extended record type #27883

@WearyMonkey

Description

@WearyMonkey

TypeScript Version:
typescript@3.2.0-dev.20181011
typescript@3.1.3
typescript@3.0.3

Search Terms:

Code

type Baa = { a: number, b: number };
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;

function foo<P extends Baa>() {
    const foo: { foo: string } & Omit<P, 'b'> = null as any;
    const props: Baa = foo;
}

Expected behavior:

No error.

Actual behavior:

test.ts:6:11 - error TS2322: Type '{ foo: string; } & Pick<P, Exclude<keyof P, "b">>' is not assignable to type 'Baa'.
  Property 'a' is missing in type '{ foo: string; } & Pick<P, Exclude<keyof P, "b">>'.

6     const props: Baa = foo;
            ~~~~~

Removing the { foo: string } & works.
Removing the Omit works.
Removing the P and using Baa directly works.

Playground Link:

https://agentcooper.github.io/typescript-play/?ts=2.9.1#code/C4TwDgpgBAQghnKBeKBvKcBcUB2BXAWwCMIAnAGiiIH5t9iyoBfAbgChRIoB5AgS2AAeACqUA0gD5kUAAp8AxgGsRlAKIAPeQBs8AEwiDFEEAHsAZlFFRJE9mzN4c84HxM4oZkycEyoEdcAQOLoAzrAIEgAUAJRobFAJUPJuIcAeXtjonibYqaR8OADmzFAAZDz8QjKUAORENVIo+FpaGGFwOCDsiUkpaWCkJmAh2PCIKNnsTGxAA

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesDomain: Mapped TypesThe issue relates to mapped typesFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions