question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript error when I refer to a component as selector

See original GitHub issue

Environment

  • typescript 3.3.3
  • linaria 1.3.1

Description

I got a type error like below when I try to refer to a component.

`Argument of type 'FunctionComponent<ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & { as?: "symbol" | "object" | "big" | "link" | "small" | "sub" | "sup" | "track" | "progress" | "a" | "abbr" | ... 163 more ... | undefined; }>' is not assignable to parameter of type 'string | number | CSSProperties | ((props: PropsWithChildren<ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & { as?: "symbol" | "object" | "big" | "link" | "small" | "sub" | ... 168 more ... | undefined; }>) => string | number)'.
  Type 'FunctionComponent<ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & { as?: "symbol" | "object" | "big" | "link" | "small" | "sub" | "sup" | "track" | "progress" | "a" | "abbr" | ... 163 more ... | undefined; }>' is not assignable to type '(props: PropsWithChildren<ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & { as?: "symbol" | "object" | "big" | "link" | "small" | "sub" | "sup" | "track" | "progress" | "a" | "abbr" | ... 163 more ... | undefined; }>) => string | number'.
    Type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)> | null' is not assignable to type 'string | number'.
      Type 'null' is not assignable to type 'string | number'.`

Reproducible Demo

import { styled } from 'linaria/react';

const a = styled.div`
    width: 1px;
`;

const b = styled.div`
    ${a} b {          // -> error at ${a}
        width: 2px;
    }
`;

I think that it has to be fixed on linaria/react.d.ts.

from

type StyledTag<T> = <Props = T>(
  strings: TemplateStringsArray,
  ...exprs: Array<
    string | number | CSSProperties | ((props: Props) => string | number)
  >
) => StyledComponent<Props>;

to

type StyledTag<T> = <Props = T>(
  strings: TemplateStringsArray,
  ...exprs: Array<
    string | number | CSSProperties | ((props: Props) => string | number) | StyledComponent<any>
  >
) => StyledComponent<Props>;

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
satya164commented, Apr 1, 2019

You’re right! It’ll be awesome if you can send a PR for that

0reactions
Anbercommented, Mar 24, 2020

The problem with styled is solved in 1.4, but there was the same problem with css tag. Fix for css will be released with the next beta.

Read more comments on GitHub >

github_iconTop Results From Across the Web

If '<selector>' is an Angular component, then verify that it is ...
I have tried to create a component but showing an error. This is the app.component.ts file. import { Component } from '@angular ...
Read more >
Component - Angular
Decorator that marks a class as an Angular component and provides configuration metadata that determines how the component should be processed, instantiated ...
Read more >
Codiga Analysis TypeScript Rules
@angular-eslint/component-selector. Unknown. Error. Detect if component selector isn't a hyphenated, lowercase value or doesn't have a descriptive prefix to ...
Read more >
API Reference - styled-components
API Reference of styled-components. ... as the CSS syntax has support for pseudo selectors, media queries, nesting, etc., ... Usage with TypeScript.
Read more >
Chapter 4, Understanding and Using Angular Components
Each component in turn has some behavior and a template that gets rendered. ... The very basic component only needs a selector (to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found