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

Add type declarations #36

Open
mindplay-dk opened this issue Nov 2, 2017 · 13 comments
Open

Add type declarations #36

mindplay-dk opened this issue Nov 2, 2017 · 13 comments
Labels
types Strings, numbers, booleans

Comments

@mindplay-dk
Copy link
Contributor

@andrewiggins I figured I'd create a separate issue for this one, since your work is already enough to get projects up and going without it.

It would be great if we could also get some type-checking for elements and attributes - standard DOM as well as pico's oncreate etc., and possibly SVG elements. (does pico support SVG?)

I tried something like [elemName in keyof ElementTagNameMap]?: any; in the IntrinsicElements declaration - I think I've seen others doing something similar, but I couldn't make it work.

Snabbdom redeclares the whole kit'n'kaboodle, I guess maybe that's a necessary evil if we want type-checking for elements/attributes?

Either way, we can leave this for a future version, once the overall type-declarations are fully in place.

@jorgebucaran
Copy link
Owner

@mindplay-dk does pico support SVG?

Yes, it totally does! 👍

@mindplay-dk
Copy link
Contributor Author

For further reference, here's the type-definitions for React and Inferno, both of which are very similar (on the important points, the element/attributes-types and CSS properties) to the ones in Snabbdom ... It makes me wish there was a single shared package with just the DOM declarations, the stuff we all have in common, but I couldn't find one.

Duplicating this massive bulk of declarations seems kind of wrong - I wonder if we should approach these other teams about that.

@jorgebucaran
Copy link
Owner

I wonder if we should approach these other teams about that.

Maybe after we are done making sure the current types are properly tested and we are done adding better docs.

@jorgebucaran
Copy link
Owner

@mindplay-dk Ping.

@mindplay-dk
Copy link
Contributor Author

Ping what? There are two open pull requests 😉

I suppose all those PRs are scrap now, though - if you're going to rewrite the whole thing.

@jorgebucaran
Copy link
Owner

No, I mean, what's this issue about again?

@mindplay-dk
Copy link
Contributor Author

It's about type-hinting.

Try e.g. Preact with Typescript in VS Code for the full IDE experience - though this is not only for IDE support, but also for stricter and more correct validation during compilation with TS.

@jorgebucaran jorgebucaran changed the title Add element/attribute type-checking to picodom.d.ts Add type declarations Feb 11, 2021
@ehsabd
Copy link

ehsabd commented Feb 11, 2021

Hi, I'm new to TypeScript, but I'm willing to contribute to type declaration for superfine.

@jorgebucaran
Copy link
Owner

That's not TypeScript. What is this about?

@ehsabd
Copy link

ehsabd commented Feb 12, 2021

I see. I try to provide an updated code soon. I'll try to make a very simplified code that allows only for the elements in the beginner example (H1, Button, Text,...)

@ehsabd
Copy link

ehsabd commented Feb 12, 2021

Okay. Here's what I came up with so far:
https://github.com/ehsabd/superfine-type-declaration-playground/blob/main/node_modules/superfine/superfine.d.ts

But we need to define type checking for props as well. To do that I can perhaps make use of GlobalEventHanlders. Perhaps I had to add props other than events to this with additional code. But at least we spare some code by using this interface.

@ehsabd
Copy link

ehsabd commented Feb 14, 2021

Okay I have added type declaration for Button as well. Indeed I think the best approach is to make use of already defined GlobalEventHandlers in combination with a GlobalAttributes type that we define ( I defined that based on this:https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes).

Many elements only have these global events & attributes. For other elements that can also have other props like Button we will add specific props. This is a concise approach I guess.

Note that in this approach we assume that attributes are limited to the defined set of attributes. But I guess that's putting a limit on the broad definition of attributes in HTML specification. I don't know but for example use of data-* attributes is a common practice. But if we don't really limit attributes, we should only type check for events. That kind of type checking should be based on the beginning of the prop (props that begin with on). I don't know how to do that in TypeScript yet.

Please take a look and let me know your thoughts.

@gustavopch
Copy link

These are the type declarations used by SolidJS, maybe they're useful for this issue: https://github.com/ryansolid/dom-expressions/blob/main/packages/dom-expressions/src/jsx.d.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types Strings, numbers, booleans
Projects
None yet
Development

No branches or pull requests

4 participants