{ a: string } can not be assigned to Partial<Omit<P, "a"> & { a: string }>
See original GitHub issueBug 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:
- T & { a: string }
- 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:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Exactly, yes
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.