Skip to content

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

Closed

Description

@ryasmi

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?

Activity

  1. developit commented on Mar 2, 2019

    @developit
    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

  2. developit commented on Mar 2, 2019

    @developit
    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.

  3. ryasmi commented on Mar 2, 2019

    @ryasmi
    Author

    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).

  4. bebraw commented on Sep 11, 2020

    @bebraw

    @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.

  5. jugglinmike commented on Apr 26, 2021

    @jugglinmike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionDiscussions and proposalsenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions