Closed spacejack closed 6 years ago
Added generic-defaults branch.
@andraaspar @isiahmeadows
@spacejack SGTM, although IMHO if it's possible, State
should default to this
rather than {}
.
Sadly that's not allowed: A 'this' type is available only in a non-static member of a class or interface.
Would've made for some very nice component type inference.
@spacejack
I thought that wasn't the case, but at the time, I couldn't immediately remember.
Unfortunately the DT test doesn't seem to allow TS version 2.3 yet, so I'll have to hold off on submitting until they do.
@isiahmeadows @andraaspar Going to try this again since DT accepts typescript version 2.3 or later.
Here's the updated branch diff.
Go for it. I'm basically a walking checkmark for anything not insane, and have been trying to get the DT devs to set up a thing where I don't have to review every Mithril-related PR there. (I forget which issue it is, but you should be able to find it if you're wondering what I'm talking about. It has to do with owners and permissions.)
Looks good!
With Typescript 2.3 it should be possible to modify the Component type to:
Meaning that you only need to declare
Attrs
andState
if you need to. So a stateless component could be:Without needing to declare an empty
State
type.A simple component without
Attrs
orState
types should work as well: