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

bug: type conflict in preact-router after preactjs/preact#3747 #432

Open
motss opened this issue Oct 9, 2022 · 0 comments
Open

bug: type conflict in preact-router after preactjs/preact#3747 #432

motss opened this issue Oct 9, 2022 · 0 comments

Comments

@motss
Copy link

motss commented Oct 9, 2022

Describe the bug

Encountering the following TypeScript error with the latest Preact 10.11.1 that supports SignalLike<T> type:

error TS2430: Interface 'HTMLAttributes<RefType>' incorrectly extends interface 'ClassAttributes<RefType>'.
  Types of property 'default' are incompatible.
    Type 'boolean | SignalLike<boolean> | undefined' is not assignable to type 'boolean | undefined'.
      Type 'SignalLike<boolean>' is not assignable to type 'boolean | undefined'.

671  export interface HTMLAttributes<RefType extends EventTarget = EventTarget>
                      ~~~~~~~~~~~~~~

Found 1 error in node_modules/preact/src/jsx.d.ts:671

Upon investigation, the error was caused by RoutableProps which is documented here in preact-router when skipLibCheck: true in tsconfig.json.

To Reproduce

Pre-requisites:

  1. dependencies:preact@10.11.1, preact-router@4.1.0
  2. devDependencies: typescript@4.8.4

Steps to reproduce the behavior:

  1. Run npm create vite@latest my-vue-app -- --template preact-ts
  2. Run npm i preact@10.11.1 preact-router@4.1.0
  3. Run npm i -D typescript@4.8.4
  4. Set skipLibCheck: false in tsconfig.json
  5. Add the following code in app.tsx:
    <Router>
       <div />
     </Router>
  6. See error

Expected behavior

RoutableProps which is documented here should be updated to follow the same typing as HTMLAttributes['default'] which supports Preact signals.

Possible solution(s)

  1. Update the type of RoutableProps['default'] to support SignalLike because it is a prop of Router that can possibly accept a signal value:
    export interface RoutableProps extends Pick<HTMLAttributes<HTMLElement>, 'default'> {
       path?: string;
    }
  2. Introduce new prop to avoid type conflict with HTML default attribute, such as defaultRoute
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

1 participant