question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RyanCavanaughcommented, Mar 3, 2022

Exactly, yes

1reaction
RyanCavanaughcommented, Apr 29, 2021

The type system doesn’t take Omit as a first-class operation; it’s a series of mapped types and conditional types under the hood that aren’t resolvable on a generic type in a way that would produce a type that we could identify as a valid assignment target of that expression. There’s not much we can do here apart from possibly special-casing, but that’s a future endeavor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Argument of type partial is not assignable to parameter of type
You can't assign a Partial of a type to the original type you made the partial from. interface Details{ name: string, phonenumber: number, ......
Read more >
Documentation - Utility Types - TypeScript
Partial <Type> ... Constructs a type with all properties of Type set to optional. This utility will return a type that represents all...
Read more >
Type 'String' cannot be used as an index type in TypeScript
The "Type 'String' cannot be used as an index type" TypeScript error occurs when we use the String type instead of string (lowercase...
Read more >
A tour of the Dart language
Some additional built-in types are String , List , and bool . 42: A number literal. ... baz = [42]; // Error: Constant...
Read more >
The Go Programming Language Specification
A comment cannot start inside a rune or string literal, ... Go programs may omit most of these semicolons using the following two...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found