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 and ThemeProvider support for props

See original GitHub issue

When using a component it’s good to ensure that no one can provide a value that the component can’t accept. My VsCode autosuggested: <PadBox padding="xlXXl" />

And typescript doesn’t yell. How can we make Bedrock typesafe?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
httpetecommented, Mar 31, 2021

xlXXl is coming from: https://github.com/Bedrock-Layouts/Bedrock/blob/922d8708104061e261d53ace8ddf3a05f9c1cb78/packages/spacing-constants/src/index.tsx and isn’t one of the valid options for PadBox.

I guess you could first make sure that each component returns the types for each prop, that happen to match to the themeProvider keys… But better would be to get the typing from styled-components (Which is possible) https://styled-components.com/docs/advanced#via-withtheme-higherorder-component

But maybe option 1 is fine and proper. You can integrate storybook to read the Interfaces and document them automatically based on that, which would help your long term maintenance and accuracy issues.

1reaction
Jarvis1010commented, Mar 31, 2021

Ah I see how can we scope them to only the provided values in the theme provider. I’m going to need to look into this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Theme with styled-components and Typescript - Medium
Theming in styled-components allows your app to support multiple design patterns within the same app. Imagine an amazing code editor with no ...
Read more >
StyledComponents with Typescript and ThemeProvider. What ...
Inside your src folder, create a new folder named @types and put your file styled.d.ts inside this folder. The content is the same...
Read more >
Typescript ThemeProvider + Props #802 - emotion-js ... - GitHub
Hello, Does anyone know of a way to use TypeScript with ThemeProvider & Props? I have a ThemeProvider like export default { color:...
Read more >
API Reference - styled-components
Any valid React component that can handle a theme prop. Returns the passed component inside a wrapper (higher order component).
Read more >
Create styled.d.ts to make Typescript work with styled ...
The ThemeProvider injects an object of type DefaultTheme into every prop and the definition for DefaultTheme is just {} . Take a look...
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