JSX: a way to make all the properties of value-based elements optional
See original GitHub issueIt’s not documented, but currently, if the JSX.ElementAttributesProperty
interface is declared empty,
declare namespace JSX { interface ElementAttributesProperty {} }
then the element attributes type becomes same as the element instance type. However, if the element instance type is a class, this leads to a situation where the compiler requires that all the members of the class be represented as attributes since they’re not optional (and even cannot be marked as such as the class syntax doesn’t allow optional members).
class MyComponent {
myProp: string;
private myMethod(): void;
}
var a = <MyComponent myProp='value'/>;
// error: Property 'myMethod' is missing in type MyComponent
This prevents me from using JSX for type-checking Angular 1 templates (you can find my experiments in this area here).
What if we introduce some way to tell the compiler that not all the properties are required, but only some of them? E.g. those having a certain decorator?
A related issue: #5151
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:23 (8 by maintainers)
Top GitHub Comments
Hm…
Now I am understood what @RyanCavanaugh and @aluanhaddad are said. We can use Partial types (a.k.a Mapped types) now.
We need good proposal.
IMHO, If JSX.ElementAttributesProperty has callable property, Use the return type instead of the type passed as an argument for checking. like this.
This issue is last 2 mile of SkateJS+TypeScript. (other 1 is #12488 ) If you have no seen SkateJS yet, please try it once. it’s fun! http://skate.js.org/ https://github.com/vvakame/skatejs-todo/