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

Theme typescript defs #995

Closed
atanasster opened this issue Jun 10, 2020 · 9 comments
Closed

Theme typescript defs #995

atanasster opened this issue Jun 10, 2020 · 9 comments
Labels

Comments

@atanasster
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
The tbody tag is not part of the Theme.styles definition

Describe the solution you'd like
Possibly add tbody (possibly also thead) tags to the typescript definitions:

tr?: ThemeUIStyleObject

Describe alternatives you've considered
//@ts-ignore

If the suggestion is ok, I can also submit a PR

@atanasster atanasster changed the title Theme ypescript defs Theme typescript defs Jun 10, 2020
@hasparus
Copy link
Member

hasparus commented Jun 12, 2020

The list of "autocompleted" keys are the same as keys of Styled

However, there's an index signature in ThemeStyles, so it should be possible to use tbody, thead and even names of your HTML custom elements (like funky-button).

Do you get an error if you try to use tbody key?


As a side note, the index signature should probably be

[key: string]: ThemeUIStyleObject | undefined

@atanasster
Copy link
Collaborator Author

Thanks a lot for the answer
yes, i am getting ts errors on 0.3.1, however it seems there are some changes since then.
Any idea when an official release will be published?

@hasparus
Copy link
Member

hasparus commented Jun 12, 2020

I am getting ts errors on 0.3.1, however it seems there are some changes since then.

0.3.1 is typed in DefinitelyTyped. There are some small problems.

I'm using 0.4 alpha in my apps for quite a long time already. I recommend to give it a shot. There's only one runtime breaking change, and TypeScript should catch it.

BTW Out of curiosity: How are you using theme.styles.tbody?

Any idea when an official release will be published?

From TypeScript perspective, I'll check if 0.4 can be used in TS codebase without skipLibCheck and if it's okay I think we're ready. I'm working on a PR with big changes to exported types (I'll send a PR this weekend I promise :P), but I'm not sure if @jxnblk wants to wait for it.

@atanasster
Copy link
Collaborator Author

Thanks. I tried to update to the alphas, but had versioning problems that some of the packages were forcing a ‘highlight’ version of the css package. Resulting in an error of ‘ defaultBreakpoints Is not exported the @theme-ui/css’. I had upgraded all my theme-ui packages to alpha but using it within a gatsby setup - maybe gatsby was forcing the version, not sure.

I am styling my own react-table derived component and it does have a tbody part and that is where i am using the tbody style. Hope it makes sense or maybe there some alternative?

Thanks a lot for checking on a possible official release, much appreciated. Have a great weekend

@hasparus
Copy link
Member

hasparus commented Jun 14, 2020

I am styling my own react-table derived component and it does have a tbody part and that is where i am using the tbody style. Hope it makes sense or maybe there some alternative?

Okay, I think I get it. So you're extracting styles.tbody from the theme and passing it to a tbody component?

maybe there some alternative?

Well, you can cascade tbody styles from styles.table

{
  table: { '> tbody': { bg: 'blue' } }
}

or write the styles inline in your component.

@atanasster
Copy link
Collaborator Author

I dont really want to write the styles inline for this particular case, but I am already using //@ts-ignore, so its ok.
Was just a suggestion to maybe add the field.

@hasparus
Copy link
Member

hasparus commented Jun 16, 2020

I'll check if 0.4 can be used in TS codebase without skipLibCheck

Okay, I think color-modes and mdx should at least have stub definitions before we publish 0.4.0.
As this wouldn't be alpha anymore, I expect as I user I would be reluctant to add skipLibCheck: true to my tsconfig.

export { useColorMode, InitializeColorMode } from '@theme-ui/color-modes';
export { Styled, components } from '@theme-ui/mdx';

There's also this error:

node_modules/@theme-ui/components/index.d.ts:4:53 - error TS7016: Could not find a declaration file for module 'styled-system'. '/home/hasparus/workspace/homepage/node_modules/styled-system/dist/index.js' implicitly has an 'any' type.
  Try `npm install @types/styled-system` if it exists or add a new declaration (.d.ts) file containing `declare module 'styled-system';`

4 import { SpaceProps, ColorProps, MarginProps } from 'styled-system'

Theme UI monorepo happens to have @types/styled-system installed as a transitive dependency, so we didn't notice it. We should add @types/styled-system as a dependency fo @theme-ui/components.

@atanasster
Copy link
Collaborator Author

Thanks for letting us know. Do you think 0.4 is close?

@lachlanjc lachlanjc added the types label Dec 2, 2020
@lachlanjc
Copy link
Member

Closing since 0.4 is published

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