Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Type definition for typescript doesn't include built-in components. #294

Closed
remagpie opened this issue Aug 21, 2017 · 5 comments
Closed

Comments

@remagpie
Copy link
Contributor

  • glamorous version: 4.2.0
  • glamor version: 2.20.40
  • react version: 15.6.1

Relevant code.

import { Div, Span } from 'glamorous';

Problem description:

Currently for typescript, there's no type definition for built-in components other than Div and Svg.
Of course I can use them as glamorous.span({...}), but it would be better if I can use built-in components too.

Suggested solution:

I think adding interface HTMLComponents having all those built-in components, and making GlamorousInterface extend it would be enough.
Like this:

interface HTMLComponents {
  Div: React.StatelessComponent<CSSProperties & ExtraGlamorousProps>,
  ...
}

export interface GlamorousInterface extends HTMLComponents, HTMLComponentFactory, SVGComponentFactory {
  ...
}
@luke-john
Copy link
Collaborator

luke-john commented Aug 21, 2017

Hey @Kais-DkM, thanks for reporting that.

That would be a great addition to the types.

Given the size of those interfaces, it would be good if they were in an adjacent file.
ie.

// built-in-glamorous-components.d.ts
export interface HTMLComponent {
    Div: React.StatelessComponent<CSSProperties & ExtraGlamorousProps>
    // ...
}
export interface SVGComponent {
    Svg: React.StatelessComponent<CSSProperties & ExtraGlamorousProps>
    // ...
}

There's also an issue with the typings for these in that they are typed to take the relevant HTMLProps.

export interface HTMLComponent {
    A: React.StatelessComponent<CSSProperties & ExtraGlamorousProps & React.HTMLProps<HTMLAnchorElement>>
    Div: React.StatelessComponent<CSSProperties & ExtraGlamorousProps & React.HTMLProps<HTMLDivElement>>
    Svg: React.StatelessComponent<CSSProperties & ExtraGlamorousProps & React.SVGAttributes<SVGElement>>
}
export interface SVGComponent {
    Svg: React.StatelessComponent<CSSProperties & ExtraGlamorousProps & React.SVGAttributes<SVGElement>>
}

If you're able to open a PR along the lines of either of the above, or another strategy/structure you think would work well, that would be greatly appreciated.

@remagpie
Copy link
Contributor Author

@luke-john
It would be a pleasure to help you out, and I think second code you suggested is a great solution.
I'm willing to open a PR, but I have a question before that.

Why wasn't this implemented until now?
Is it just because nobody tried to work on it? or were there any issues related to this typing?

@Ailrun
Copy link
Contributor

Ailrun commented Aug 21, 2017

@luke-john
@Kais-DkM
If needed, I will send a PR about this issue with my issue, since both issues related with typing problem.

@luke-john
Copy link
Collaborator

Is it just because nobody tried to work on it? or were there any issues related to this typing?

@Kais-DkM it was because no one had tried to work on it.

Looks like there's already a PR open, but thank you for your offer to work on this 👍.

If you're still interested in helping out with the typings I'll be opening some issues later this week with good first prs to help improve the developer experience. #295

@remagpie
Copy link
Contributor Author

@luke-john
I'll take a look at it on spare time, and thanks for your offer!

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

No branches or pull requests

3 participants