question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript definitions

See original GitHub issue

I think it would be really cool if we could start writing (or generating) some typings for this project.

Its quite frustrating having to leave my editor everytime i need to check what props are available. image

PropTypes are great for runtime analysis, but most tools cannot statically parse prop types. Editors like VSCode use TS defintion files to provide “intellisense” to users.

Libraries like material-ui have fully typed components, have a look at what VSCode is able to provide me for their Button component

image

But just because we are using JS does not mean we need to sacrifice static typing for our consumers - .d.ts files can be used to export type defintions for JS libraries

This is something that I would love to see implemented to improve the developer experience with carbon!

Keep up the great work!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
daka1510commented, Feb 8, 2022

Totally agree that adding type definitions to Carbon would be a great move. I worked for 2 years with Carbon within IBM. Tried using https://www.npmjs.com/package/@types/carbon-components-react but stopped because those type definitions were not always in sync with the actual code.

Similarly, I think there is hesitation with respect to what maintenance means for types and if we would need to respect semver both for package versions and types.

My take: if efforts are taken to provide type declarations, include them in the source package itself.

1reaction
seanlaffcommented, Feb 7, 2022

Hi @joshblack we’re a team inside IBM and would like to revisit this issue.

Typescript has a been a lifesaver for us at scale. The types catch a host of different errors before any code gets pushed, and the autocompletions that IDEs provide end up being a huge timesaver with regards to developer-experience.

Given the carbon team manually writes propType definitions, I understand your hesitation to write even more definitions by hand. I like @dan-cooke’s suggestion of generating typescript types from propTypes as a quick shim, but propTypes are not that expressive (i.e you can declare a prop is a function… but cant require it matches a certain signature). Thus, the typescript types generated this way would be lackluster (but surely better than nothing).

Stepping back, a better approach might be to have carbon be typescript native, increasingly the resiliency of carbon itself as well as downstream apps. Additionally, we could generate propTypes from the typescript types for non-typescript consumers (since type accuracy is not lost when going from ts->propTypes, while the reverse is not true). There are a few way to do this, such as via babel-plugin https://github.com/milesj/babel-plugin-typescript-to-proptypes.

In any case, it feels like typescript has reached a level of popularity that I think the typings deserve some thinking.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Type Declarations - TypeScript
Built-in Type Definitions. TypeScript includes declaration files for all of the standardized built-in APIs available in JavaScript runtimes.
Read more >
Documentation - Introduction - TypeScript
The Declaration Files section is designed to teach you how to write a high-quality TypeScript Declaration File. We need to assume basic familiarity...
Read more >
Documentation - Modules .d.ts - TypeScript
Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]>. /*~ This is the module template file. You should rename it to index.d.ts. *~ and...
Read more >
The repository for high quality TypeScript type definitions.
The repository for high quality TypeScript type definitions. - GitHub - DefinitelyTyped/DefinitelyTyped: The repository for high quality TypeScript type ...
Read more >
TypeScript Definitions | Developer's Guide - GrapeCity
Hence, all the DataViewsJS packages on npm include TypeScript definitions. These TypeScript declaration (d.ts) files provide the type checking and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found