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

Question: How well does this work with TypeScript? #73

Closed
ryasmi opened this issue Feb 27, 2019 · 5 comments
Closed

Question: How well does this work with TypeScript? #73

ryasmi opened this issue Feb 27, 2019 · 5 comments
Labels
discussion Discussions and proposals enhancement New feature or request

Comments

@ryasmi
Copy link

ryasmi commented Feb 27, 2019

Hey, apologies to take your time on a question I could answer myself with a few minutes of trying it out (and I still might do that if I get a few minutes). It would be nice to just have a quick answer to this question somewhere in this project, maybe in the readme. I guess specifically I'd like to know the following.

  1. Does this package have typings?
  2. Does TypeScript provide compile time errors for passing incorrect prop values to components when using this package?
@developit
Copy link
Owner

  1. there aren't typings for htm / html, but there are extremely basic types for the react and preact integrations.
  2. No. For this and the typings, TypeScript doesn't have a way to inspect the contents of Tagged Templates (or Template Literals). This means we can't really offer any useful inference for what a tagged template contains.

I kicked off a discussion with the TypeScript folks about this (and more generally about extending type checking into tagged templates). You might find the discussion interesting:
microsoft/TypeScript#29432

@developit developit added enhancement New feature or request discussion Discussions and proposals labels Mar 2, 2019
@developit
Copy link
Owner

FWIW, you can use TSX and get all the TypeScript benefits, tell TS to leave TSX in-tact via jsx:'preserve' when compiling, then pass the result through babel-plugin-transform-jsx-to-htm and still be using HTM at runtime.

@ryasmi
Copy link
Author

ryasmi commented Mar 2, 2019

Okay thanks @developit. For now then it looks like this unfortunately isn't really viable for use with TypeScript and the conversation with the TypeScript folkes appears to have gone stale (no comments for a month). Cool project though and using the Babel plugin is a good idea if this provides some performance benefits, although I'm not sure I'd personally be willing to sacrifice a small performance improvement for a more complicated build since I don't think this would work with parcel (I might be wrong though).

@bebraw
Copy link

bebraw commented Sep 11, 2020

@ryansmith94 TypeScript will receive support for tagged templates. See microsoft/TypeScript#40336 .

I believe you should be able to type htm on top of that although that may not be a trivial task.

@jugglinmike
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussions and proposals enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants