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

combineProps type error since typescript 5.3 #554

Open
GiyoMoon opened this issue Dec 23, 2023 · 2 comments
Open

combineProps type error since typescript 5.3 #554

GiyoMoon opened this issue Dec 23, 2023 · 2 comments

Comments

@GiyoMoon
Copy link

Describe the bug

I noticed that combineProps throws a type error when upgrading to typescript 5.3. In typescript <=5.2, the same code worked without issues.

import { combineProps } from '@solid-primitives/props'
import { Dynamic, DynamicProps } from 'solid-js/web'
import type { ValidComponent } from 'solid-js'

const MyComponent = <T extends ValidComponent = 'div'>(
  props: DynamicProps<T>,
) => {
  const combinedProps = combineProps([props])
  const children = <div>children</div>
  // This worked with typescript version <= 5.2 and broke in 5.3
  return <Dynamic {...combinedProps}>{children}</Dynamic>
}

export default MyComponent
image

Minimal Reproduction Link

https://github.com/GiyoMoon/solid-primitives-type-error

@thetarnav
Copy link
Member

thetarnav commented Sep 13, 2024

Currently combineProps is just using the MergeProps type from solid, so mergeProps has the same issue from what I see: https://playground.solidjs.com/anonymous/06bd1b95-c609-4d66-93ef-656ee931fba2

Also it's interesting how the same code has no problems without jsx:
image

I get the same error for compineProps, even in .ts file, if I slightly change the function signature:

// from
export function combineProps<T extends [] | MaybeAccessor<PropsInput>[]>(...sources: T): MergeProps<T>
// to
export function combineProps<T extends unknown[]>(...sources: T): MergeProps<T>

Which shouldn't change anything

Ok it has nothing to do with MaybeAccessor<PropsInput> part, the same difference is also between unknown[] and [] | unknown[], where the latter just makes the type to be inferred as a tuple.

@thetarnav
Copy link
Member

thetarnav commented Sep 13, 2024

Overwriting the children prop in combineProps rather than jsx seems to fix it.
Which is probalby a better way in general, because it doesn't cause another mergeProps to be compiled in to handle the overwritting.

const merged = combineProps(props, {
  get children(){
    return <div>children</div>
  }
})
return <Dynamic {...merged}/>

Maybe this should be reopened on solidjs repo as well. Although the usage seems incorrect, because of mentioned issue with multiple mergeProps.

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