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

TypeScript: priority of typings seems wrong #1836

Closed
bugproof opened this issue Jan 18, 2023 · 1 comment
Closed

TypeScript: priority of typings seems wrong #1836

bugproof opened this issue Jan 18, 2023 · 1 comment
Labels
question Further information is requested

Comments

@bugproof
Copy link

bugproof commented Jan 18, 2023

Describe the bug

When passing through props from e.g. <li> element

https://github.com/sveltejs/svelte/blob/7e6acbece31fbd68e2c07e37f3c849c405eb6983/elements/index.d.ts#L796-L798

export interface HTMLLiAttributes extends HTMLAttributes<HTMLLIElement> {
	value?: string | string[] | number | undefined | null;
}

it doesn't seem to be possible to override the default typing for value e.g. consider this component that defaults to rendering as <li> element

https://github.com/rgossiaux/svelte-headlessui/blob/master/src/lib/components/listbox/ListboxOption.svelte#L7

the value there expects unknown type but when you try to assign any/unknown type you get an error because index.d.ts typing takes precendence.

Reproduction

The easiest way to reproduce is to use headless ui fork for Svelte: https://svelte-headlessui.goss.io/docs/listbox and copy paste the basic example.

Expected behaviour

It shouldn't give typescript error

System Info

  • OS: Windows
  • IDE: VSCode

Which package is the issue about?

None

Additional Information, eg. Screenshots

sveltejs/svelte#7649

image

@bugproof bugproof added the bug Something isn't working label Jan 18, 2023
@dummdidumm
Copy link
Member

This is a problem with the typings of that library. Doing & { value: unknown } doesn't cast that value to unknown; in general when something should be overwritten, Omit<.., 'value'> & { value: .. } should be used

https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgILIN4ChnIG5wA2ArhAFzIDOYUoA5gNxYC+WWYAngA4oBCyAXkwES5KjXrNkAMmFFSFYiADWIAPYB3EMyZYEakNWQAjCvyEYRC5DVKssQA

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2023
@dummdidumm dummdidumm added question Further information is requested and removed bug Something isn't working labels Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants