You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: How well does this work with TypeScript? #73
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.
Does this package have typings?
Does TypeScript provide compile time errors for passing incorrect prop values to components when using this package?
there aren't typings for htm / html, but there are extremely basic types for the react and preact integrations.
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
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.
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).
Activity
developit commentedon Mar 2, 2019
htm/html, but there are extremely basic types for the react and preact integrations.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 commentedon Mar 2, 2019
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 throughbabel-plugin-transform-jsx-to-htmand still be using HTM at runtime.ryasmi commentedon 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 commentedon Sep 11, 2020
@ryansmith94 TypeScript will receive support for tagged templates. See microsoft/TypeScript#40336 .
I believe you should be able to type
htmon top of that although that may not be a trivial task.jugglinmike commentedon Apr 26, 2021
TypeScript 4 took a step in the right direction, but it looks like it's still not quite possible: