Linaria: Typings not working properly

Created on 4 Feb 2020  路  2Comments  路  Source: callstack/linaria

Environment

Create react app (ejected) + TypeScript, nothing special there.

Description

I'm trying to annotate props like this:

import { styled } from 'linaria/lib/react'

interface TitleProps {
  background: string
}

export const Title = styled.div<TitleProps>`
  background: ${(props) => props.background};
`

But I get an error:

interface TitleProps
    Expected 0 type arguments, but got 1.ts(2558)
 ```

Which is weird because the typings on the [repository](https://github.com/callstack/linaria/blob/master/react.d.ts#L13) says one thing, but the typings from the distribution package at `linaria/lib/react/styled.d.ts@17` says:

```ts
declare type HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = (strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: JSX.IntrinsicElements[TName]) => string | number)>) => StyledComponent<JSX.IntrinsicElements[TName]>;

Which means that it's not accepting any generics on this besides TName. It works if I do this:

declare type HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <AdditionalProps>(strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: JSX.IntrinsicElements[TName] & AdditionalProps) => string | number)>) => StyledComponent<JSX.IntrinsicElements[TName] & AdditionalProps>;

(AdditionalProps added)

But it looks like this file is being auto-generated and it looks that importing from linaria/lib/react is a workaround, right? What can be done to address this issue?

Most helpful comment

@zaguiini thank you for your report! The fix will be released with the next beta.

All 2 comments

Looks like it's time to merge #389 :)

@zaguiini thank you for your report! The fix will be released with the next beta.

Was this page helpful?
0 / 5 - 0 ratings