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

Add TypeScript definitions #16

Merged
merged 5 commits into from
Apr 17, 2019

Conversation

franky47
Copy link
Contributor

@franky47 franky47 commented Nov 21, 2018

Relates to issue #3.

Brings the following TypeScript features:

  • import media from 'styled-media-query' in a TypeScript file
  • Define a custom media object with given breakpoints
  • Connect ThemeInterface from styled-components to default or custom media object
  • Use custom props types when creating media-queried styled components
  • Intellisense for theme and custom props

I'll edit this message with the usage API for documentation once the depending PRs (#14, #15 and DefinitelyTyped#30511) have been merged.

@sqal
Copy link

sqal commented Jan 15, 2019

Hi @franky47 I just wanted to give you a heads up that there's some issue with those typings. Here's an example which is not working for me:

${media.greaterThan('xl')`
  position: fixed;
  top: 50%; left: 0;
  ${size('100vh')} // <--- TS error here
`}

TypeScript error:

Argument of type '{ width: string | number; height: string | number; }' is not assignable to parameter of type 'InterpolationFunction<{}, any> | FlattenInterpolation<ThemeProps<any>>'.
  Type '{ width: string | number; height: string | number; }' is missing the following properties from type 'FlattenInterpolation<ThemeProps<any>>': length, concat, join, slice, and 18 more.

@franky47
Copy link
Contributor Author

Interesting, I can't replicate that error, do you have a link to a project I can clone to take a look ?

@sqal
Copy link

sqal commented Jan 15, 2019

Sure, I'll create reproduction repository for you later. Btw, I am using Typescript 3.2.2

@morajabi
Copy link
Owner

morajabi commented Jan 16, 2019

@franky47 Thank you so much for the PR! 😍 One question, have you tested it in a TS project yourself? As currently, I don't have a TS React project myself.

@sqal
Copy link

sqal commented Jan 16, 2019

@timhagn timhagn mentioned this pull request Mar 6, 2019
@franky47 franky47 force-pushed the feature/typescript-definitions branch from 311913d to d29dfbd Compare March 8, 2019 16:54
@franky47
Copy link
Contributor Author

franky47 commented Mar 8, 2019

@sqal thanks, it should work now.

@andyford
Copy link

andyford commented Apr 5, 2019

can this be merged?

@andy-hook
Copy link

Great work on these, are they ready to be merged? would love to have them in the package rather than in my custom typings.

@morajabi morajabi merged commit 687a208 into morajabi:master Apr 17, 2019
@JClackett
Copy link

when will this be released :) ?

@morajabi
Copy link
Owner

@JClackett Published! Could you please try it and let me know? 🙌✨

@JClackett
Copy link

working! 👍 Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants