Skip to content

{ a: string } can not be assigned to Partial<Omit<P, "a"> & { a: string }>Β #43846

Closed
@vipcxj

Description

@vipcxj

Bug Report

πŸ”Ž Search Terms

extends, Partial

πŸ•— Version & Regression Information

4.2.4

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// We can quickly address your report if:
//  - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!
//  - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.
//  - The incorrectness of the behavior is readily apparent from reading the sample.
// Reports are slower to investigate if:
//  - We have to pare too much extraneous code.
//  - We have to clone a large repo and validate that the problem isn't elsewhere.
//  - The sample is confusing or doesn't clearly demonstrate what's wrong.

type FunctionType<T> = {
  func(arg: Partial<T>): any;
};

type StringType = {
  str: string;
};

type T = { str: "abc" }
type A = T & StringType;
type B = Omit<T, "str"> & StringType;
const a: Partial<A> = { str: "" }; // not ok.
const b: Partial<B> = { str: "" }; // ok.

function example<T extends Record<string, any>>(ft: FunctionType<Omit<T, "str"> & StringType>) {
  ft.func({ str: "" }); // not ok.
}

according #43125, { a: "string" } can not be assigned to Partial<P> which P extends { a: string } because P.a may extends from string. So I make 2 new version:

  1. T & { a: string }
  2. Omit<T, "a"> & { a: string }.

But still not work.

πŸ™ Actual behavior

At least { a: string } should be assigned to Partial<Omit<P, "a"> & { a: string }>

πŸ™‚ Expected behavior

It not work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions