Skip to content
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

PlainObject not working with Interfaces #142

Closed
Kagu-chan opened this issue Oct 6, 2023 · 3 comments
Closed

PlainObject not working with Interfaces #142

Kagu-chan opened this issue Oct 6, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Kagu-chan
Copy link

The Type PlainObject, which is used as type constrain for functions like merge does not accept interfaces.

type R = Record<PropertyKey, unknown>; // same as PlainObject, but its not exported. So lets rebuild it here
type Foo = {
  a: number;
  b: number;
};
interface Boo {
  a: number;
  b: number;
}

function f<x extends R>(x: x): void {
  /* NOP */
}

f<Foo>({ a: 1, b: 1 }); // This is OK
f<Boo>({ a: 1, b: 1 }); // This fails and requires a symbol and a string key

/*
Type 'Boo' does not satisfy the constraint 'R'.
  Index signature for type 'string' is missing in type 'Boo'.ts(2344)
*/

TS Playground: https://www.typescriptlang.org/play?ts=4.8.4#code/C4TwDgpgBASlC8sIGMD2AnAJgHgArtUnVAGkIQAaKAVwDsBrW1Ad1oD4BuKAem6gGcAhgFtog-lFwAbQQEtaAeQBGAKxTAqS6sCizgEpjogAPMBmARMAOigBlVFCkR9UdBC2ypmXToAWENwBYAChQSCgAMVQHRABvEKgoQQAuKFpqYSUAjgSoJVT0zOyQgF8c4PkLdAAzQWRoACFoqHjgxJS0jKz0csT8zqKe0pCQ6rpkYFlUWihq7GMoEwtaTAkYNgAKY1TjAEpUgDdUWW9WxO4AKigAOQVcKAvuYeDR7CjUTdik1IBGTV+oCVdlxeFAACq+WQSKFQBQkV5ND4bL4dP55AFAkF8CEw2qeCSCFauCAAR2osjcBIEIEyqCkSSJggEwHQ8gA5lB6OQgA

@Maggi64 Maggi64 added the bug Something isn't working label Oct 6, 2023
@kemaric
Copy link

kemaric commented Oct 21, 2023

I can take a look into this.

@Maggi64
Copy link
Owner

Maggi64 commented Dec 2, 2023

🤔 I've tried a few things but haven't found a good solution. If anyone has a good solution, please let me know.

@Maggi64
Copy link
Owner

Maggi64 commented Mar 1, 2024

Making use of Record<PropertyKey, any> fixes it. And will be released shortly (bc9aeec). The tradeoff is that now other objects like Date, RegEx also can be passed into the function. I think this is better then dealing with TS when using interfaces.

@Maggi64 Maggi64 closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants