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

create types for using calcite components with preact + typescript #693

Merged
merged 2 commits into from
Jul 1, 2020

Conversation

paulcpederson
Copy link
Member

While setting up CC with a preact project that used TypeScript I ran into a lot of problems. First, you get the "Property 'insert-calcite-tag-name' does not exist on type 'JSX.IntrinsicElements':

So you have to augment the intrinsic elements types with the custom tag names from calcite components. After you do that, then you realize that the event names don't work in preact if you use the events from the provided types. Ie onDropdownClose will never fire, you have to use ondropdownClose:

This is a temporary fix that uses a custom output target to generate an additional typescript file for preact. If we get the ds framework bindings up and running, we may be able to get rid of this, but for now it allows cc to be used in the TS + preact project by importing these types. note this ts file expects preact as a peer dependency.

/cc @nathan-barrett

Copy link
Contributor

@macandcheese macandcheese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@macandcheese macandcheese added this to the 🔨 v1-beta.31 milestone Jun 30, 2020
@jcfranco
Copy link
Member

jcfranco commented Jul 1, 2020

Pretty cool, @paulcpederson!

How will these types be shipped/consumed? Do we need to add some info to the wiki?

note this ts file expects preact as a peer dependency.

It looks like preact is only needed to build the types, so maybe it needs to be added as a dev dependency to package.json too.

@paulcpederson
Copy link
Member Author

@jcfranco yes, we should probably add a note about this somewhere. Essentially the consuming dev will have to point to these types from their ts config, I think. I don't think dev dependencies are installed for the end developer, and we don't need preact to build the types, so I think we're good not including it. If you're in the situation where you need to use cc with preact in a typescript environment, we can be relatively certain that you have preact installed.

I've just created an example in the examples repo with preact + typescript to verify that this works and it worked like a dream!

Here is the one line you need to add to get TS support in a preact project: https://github.com/ArcGIS/calcite-components-examples/pull/5/files#diff-d80b0fb3496bbde41afa09f1ef6556adR58

Once we release this I'll bump the version in that examples pr and open it for real.

@paulcpederson
Copy link
Member Author

I've added a short note about this additional typings file in the readme.md inside the TypeScript section.

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.

3 participants