Skip to content

Generate Typescript and Flow type definitions from existing prop-types. #1346

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

Closed
girishla opened this issue May 3, 2018 · 22 comments
Closed

Comments

@girishla
Copy link

girishla commented May 3, 2018

Are there any plans on providing Typescript type definitions ?

@interactivellama
Copy link
Contributor

There is nothing on the roadmap for *.d.ts files at this time. I'm open to them being added. We would probably need to add some tests that validate them, so that they don't get out of date.

@interactivellama interactivellama changed the title Typescript Type definitions Explore Typescript Type definitions May 7, 2018
@interactivellama
Copy link
Contributor

interactivellama commented May 7, 2018

How can we do this based on propTypes in an automated way?

Also provide Flow typed definitions.

@futuremint
Copy link
Contributor

futuremint commented May 7, 2018

I tried using dts-gen from Microsoft last week to create Typescript definitions but couldn't get it working using their basic CLI usage on our npm library.

However I'm sure it'll be straightforward to write up a script that uses the source files to generate type definition files from the PropTypes we've already written.

@davidlygagnon
Copy link
Contributor

There is this codemod available to generate flow types from prop-types : https://medium.com/netscape/react-proptypes-to-flow-codemod-9757f5ec5381

. Only caveat is it seems to also removes prop-types... Never used it before but maybe there's a flag that can be passed to leave prop-types as is when converting.

I know I've used this: https://github.com/joarwilk/flowgen before to convert TypeScript defs to flow types, (but that's assuming we have TypeScript defs).

@interactivellama
Copy link
Contributor

We might be able to use something from react-docgen AST parser if we need to do something custom.

@stale stale bot added the stale label Jul 6, 2018
@futuremint futuremint removed the stale label Jul 6, 2018
@salesforce salesforce deleted a comment from stale bot Jul 6, 2018
@stale stale bot added the stale label Sep 4, 2018
@futuremint futuremint removed the stale label Sep 4, 2018
@futuremint
Copy link
Contributor

I'm going to work on adding a typedef file in October. I will also look into generating a library definition for flow as well.

@salesforce salesforce deleted a comment from stale bot Sep 4, 2018
@ChuckJonas
Copy link

instead of trying to keep typedefs in sync, a better solution would just be to convert this to a typescript project 😉.

@futuremint
Copy link
Contributor

I don't disagree... but providing a typedef file is a bit orthogonal to this project being typescript or not. Being typescript would certainly help this cause... but it doesn't prevent it either. We have other typescript projects around Salesforce, the heavy lifting here would be around integrating tsc into the build system, and also around cleaning up the types. IMHO, typescript's benefits don't really show up until you can turn on strictNullChecks without warnings/errors.

All that said... it is open source and we welcome contributions! I'd be happy to review a PR if you wanted to work on converting to typescript. We'd need to talk about it internally to see if the main contributors were comfortable with typescript though... we have some contributors who also use flow.

@ChuckJonas
Copy link

@futuremint I think the biggest benefit would be replacing the clunky propTypes definitions with typescript much better typing system. I think there are other benefits as well, but I was half joking.... It's definitely a big ask.

In my dreamworld ESNextNext just adopts the typescript specification, so you might as well get on board now 😈

@futuremint
Copy link
Contributor

@futuremint futuremint changed the title Explore Typescript Type definitions Generate Typescript and Flow Type definitions from existing prop-types. Oct 22, 2018
@futuremint futuremint changed the title Generate Typescript and Flow Type definitions from existing prop-types. Generate Typescript and Flow type definitions from existing prop-types. Oct 22, 2018
@futuremint futuremint self-assigned this Jan 14, 2019
@dehru
Copy link

dehru commented Apr 15, 2019

Hello, has there been any progress on types?

@interactivellama
Copy link
Contributor

@dehru I think @futuremint has been pulled into other organizational priorities.

I'm un-assigning the issue from you @futuremint until you are able to take this up.

@futuremint
Copy link
Contributor

Thats fine to un-assign it. @dehru we're an open sourced project and would welcome a contribution for this if you're inclined to take it on yourself.

@xoob
Copy link
Contributor

xoob commented May 12, 2020

Hey everyone, we are currently working on adding TypeScript compatibility for design-system-react and will provide a pull request that will add strict type definitions for every component and their prop types.

@ChuckJonas
Copy link

Curious if you are rewriting in ts or just adding type defs?

@xoob
Copy link
Contributor

xoob commented May 12, 2020

We are adding .d.ts files for the existing library. Our work utilizes tsc with allowJs and checkJs, and KnisterPeter/react-to-typescript-definitions. The goal is to be able to import the library into TypeScript projects and get code completion, strict validation, and no import errors, while trying to keep the changes to the library as minimal as possible.

@Ewilliams90
Copy link

Extremely excited about this @xoob and I would love to help if I can in any way.

@xoob
Copy link
Contributor

xoob commented Jul 6, 2020

I'm currently waiting for a number of pull requests to land before we continue on this.

@interactivellama
Copy link
Contributor

@xoob Is that pull requests on our side or something internal to you?

@Ewilliams90 Welcome to Salesforce!

@garygong
Copy link
Contributor

I think one of the PRs is on our side (#2514). I took a look at that one and it generally looks good.

@djdeimon
Copy link

I just can't wait those types definitions. It will be really nice feature and finally I will avoid multiple import issues in my project.

@coler-j
Copy link

coler-j commented Nov 25, 2020

We are adding .d.ts files for the existing library. Our work utilizes tsc with allowJs and checkJs, and KnisterPeter/react-to-typescript-definitions. The goal is to be able to import the library into TypeScript projects and get code completion, strict validation, and no import errors, while trying to keep the changes to the library as minimal as possible.

@xoob, I would be really interested in your workflow for this, currently looking into doing something similar. Made a SO q to collate my search.

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

No branches or pull requests