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.

Support passing type parameters to styled function

See original GitHub issue

TypeScript 2.9 will support passing type parameters to tagged template literals, i.e.

styled<Props>`
  color: black;
`;

will become valid. The plugin should support this syntax and trigger the syntax highlighting.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:28
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kachkaevcommented, Aug 21, 2018

I think a more likely use case is styled.tag<Props>`...`  rather than  styled<Props>`...`

Example:

const MyComponent = styled.div`
  background: yellow;
  color: red;
`;

const MyComponentWithParams = styled.div<{ something?: boolean }>`
  background: yellow;
  color: ${(p) => (p.something ? "green" : "red")};
`;

Current look in VSCode:

screen shot 2018-08-21 at 11 28 11

(the first block is highlighted and the second one is not)

Types in template literals work for me in next@7.0.0-canary.0 + @zeit/next-typescript@1.1.1-canary.2 🎉 This means that they may be widely used soon after the release of 7.0.0 😉

0reactions
CosmaTrixcommented, Feb 28, 2019

Hi all,

Any update on this issue? As you can see in the image the Container is higlighted correctly, while Item<Props> is not. 😞

image

This is the stack I’ve been using

  • Visual Studio Code 1.31.1
  • Create React App 2.1.5
  • React & ReactDOM 16.8.3
  • styled-components 4.1.3
  • TypeScript 3.3.3333
  • typescript-styled-plugin 0.14.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing in parameter to Styled Components - Stack Overflow
You can pass an argument with Typescript as follows: <StyledPaper open={open} /> ...
Read more >
Advanced Usage - styled-components
styled -components has full theming support by exporting a <ThemeProvider> wrapper component. ... You can also pass a function for the theme prop....
Read more >
typing — Support for type hints — Python 3.11.1 documentation
Source code: Lib/typing.py This module provides runtime support for type hints. ... In the function greeting , the argument name is expected to...
Read more >
8 awesome features of styled-components - LogRocket Blog
Props can be passed to styled components just as they are with regular React components (class or functional). This is possible because styled...
Read more >
Google C++ Style Guide
Inputs and Outputs; Write Short Functions; Function Overloading; Default Arguments; Trailing Return Type Syntax. Google-Specific Magic.
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