-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot assign an instance of the Intersection of a Record and a Partial of a Record #44196
Comments
I guess it's related to why arrayProperty isn't allowed in interface FuzzyObject {
arrayProperty?: string[]; // Property 'arrayProperty' of type 'string[] | undefined' is not assignable to string index type 'string'.(2411)
[key: string]: string;
} |
This the intended behavior. To be assignable to a |
Thank you for taking the time to provide explanations. I see, it seems very reasonable. But isn't this behavior somewhat inconsistent? (the fact that for example I can set/read the I think this might have to do with the following behavior difference: type NeverType = number & boolean; // Resolves to "never"
const neverConst: NeverType = 1; // expected error: `Type 'number' is not assignable to type 'never'.`
type NearlyNeverType = string & string[]; // Resolves to string & string[]
const nearlyNeverConst: NearlyNeverType = "1"; // Expected error, but message says: `Type 'string' is not assignable to type 'string[]'` (and vice-versa when assigning an array) I suppose that |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
Defining an object as an intersection of a Record and a Partial of a Record with a key more specific and a different value type does not allow to set the instance object with the Partial type.
Not completely sure if this is a bug or a design limitation. 🙇
🔎 Search Terms
Might be related to: #17867, #38977,
🕗 Version & Regression Information
Record
⏯ Playground Link
Playground link with relevant code ; edited
💻 Code
🙁 Actual behavior
The following does not work:
Has the error:
🙂 Expected behavior
The above should work with no error.
The text was updated successfully, but these errors were encountered: