Emotion: Add TypeScript definitions

Created on 28 Jun 2017  路  9Comments  路  Source: emotion-js/emotion

I'll do this when I have some free time (probably right after #EuroPython, I have a talk to prepare :) ).

Should be pretty straightforward to port styled-components' definitions.

What are the main API differences with it?

Most helpful comment

any progress here?

All 9 comments

Just made a wip PR this morning. Would you be interested in collaborating?

Yup :) you can have a look at this in the meanwhile https://github.com/styled-components/styled-components/blob/master/typings/styled-components.d.ts :)

@patrick91 That's awesome! Thanks for the link 馃憤 I managed to get the styled function to typecheck, with autocomplete for tags. But I'm currently facing an issue with React.createElement:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.

My guess is that this was the reason you guys went with custom component declarations for styled-components?

@marvinhagemeister This is going to be tricky I think.

the signature for styled is (I don't know typescript I'm just making this syntax up as I go)

styled(tag: string|$ReactComponent, cls: string, vars: <Mixed>, content: () => {})

I think typescript is seeing a tagged template literal and expecting it to have a signature like

styled(strings: <String>, ...vars: <Mixed>)

Similarly, could we get flow definitions as well? While I'm a rookie with Flow and inexperienced with TypeScript, I would greatly appreciate the definitions in flow, so I'd be happy to try my hand at contributing that side of the equation

@hawkins tag me in when you sent the PR. Installing flow to my new project and seeing a lot of red lines :D

P/S: Emotion is partially written in Flow https://github.com/tkh44/emotion/blob/0485de608c9ea7f039c78dc06788040ef009d258/src/index.js#L1

any progress here?

Hey guys, I've created a PR!

Check it out: https://github.com/emotion-js/emotion/pull/398

Hey @tkh44, I think you can close this issue since it's already merged and published.

Was this page helpful?
0 / 5 - 0 ratings