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

Argument types not being inferred in event handler props when composing components #560

Closed
jakelazaroff opened this issue Apr 14, 2021 · 2 comments
Labels

Comments

@jakelazaroff
Copy link

Bug report

Describe the bug

When using composing a component that uses any of the *HTMLAttributes interfaces from React, TypeScript no longer infers the types of arguments to event handlers.

Weirdly, it infers correctly if you use the plain HTMLAttributes interface… but only if some other prop is causing an error 🥴

To Reproduce

Reduced test case:

import { InputHTMLAttributes } from "react";
import { createCss } from "@stitches/react";

const { styled } = createCss({});

type InputProps = InputHTMLAttributes<HTMLInputElement>;

function Input(props: InputProps) {
  return <input {...props} />;
}

const StyledInput = styled(Input, {});

export default function App() {
  // Parameter 'e' implicitly has an 'any' type. ts(7006)
  return <StyledInput onChange={(e) => console.log(e)} />;
}

Here's a sandbox with a more comprehensive example: https://codesandbox.io/s/dreamy-oskar-chq4z?file=/src/App.tsx

Expected behavior

TypeScript should infer the correct type for the event handler arguments.

@peduarte peduarte added the typescript TypeScript related label Apr 15, 2021
@jonathantneal
Copy link
Contributor

This is now working in #659

import { InputHTMLAttributes } from 'react'
import { createCss } from '@stitches/react'

const { styled } = createCss({})

function Input(props: InputHTMLAttributes<HTMLInputElement>) {
  return <input {...props} />
}

const StyledInput = styled(Input)

export default function App() {
  return (
    <>
      <Input onChange={(e) => console.log(e)} />
      <StyledInput onChange={(e) => console.log(e)} />
    </>
  )
}

image

@peduarte
Copy link
Contributor

Fixed in V1. Please refer to migration guide and changelog

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

No branches or pull requests

3 participants