镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

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:

Activity

  1. ghost added
    BugA bug in TypeScript
    on Oct 16, 2018
  2. changed the title [-]Incorrect error when assigning to omited and extended record type[/-] [+]Incorrect error when assigning to omitted and extended record type[/+] on Oct 25, 2018
  3. ahejlsberg commented on Feb 1, 2019

    @ahejlsberg
    Member

    Fixed by #29121.

  4. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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