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

lit-helpers spreadProps types #2705

Open
oligafner opened this issue Aug 24, 2023 · 1 comment
Open

lit-helpers spreadProps types #2705

oligafner opened this issue Aug 24, 2023 · 1 comment

Comments

@oligafner
Copy link

oligafner commented Aug 24, 2023

Expected behavior

When I use spreadPros like this:

const item: InterfaceItem...
${spreadProps(item)}

it would expect it to throw no error

Actual Behavior

When I use spreadPros like this:

const item: InterfaceItem...
${spreadProps(item)}

I get a TypeScript error

Argument of type 'InterfaceItem' is not assignable to parameter of type '{ [key: string]: unknown; }'.
  Index signature for type 'string' is missing in type 'InterfaceItem'.

my Interface looks like this

interface InterfaceItem {
  text?: string;
}

I can work around this when i spread my object like this:

${spreadProps({...item})}

Additional context

if I change the type definition from

export declare const spreadProps: (_spreadData: {
    [key: string]: unknown;
})

to

export declare const spreadProps: (_spreadData: {
    [key: string]: any;
})

there is no error thrown, but i don't know if this is the right approach. Could also be related to this: microsoft/TypeScript#50087 (comment)

@Westbrook
Copy link
Contributor

It’s possible that a generic could help here, but there is a pretty vast (see the looseness of the internal type) amount of values to cover here. If you had a suggestion in the form of a PR, we’d be happy to discuss this more closely!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants