consider a component with props defined as follows...
# react
a
consider a component with props defined as follows
Copy code
external interface UserProps : Props {
   var name: String
   var photo: String?
}
In Typescript, Rendering a component (say User) with these kind of props would behave like this Compilation
Copy code
<User name="John Doe"/>
Compilation (prop name is required)
Copy code
<User photo="<https://some.url>"/>
While in kotlin Compilation
Copy code
User { name="John Doe" }
Compilation, Runtime
Copy code
User { photo="<https://some.url>" }
Now (@turansky), Isn't there a way to provide compile time safety for
kotlin-react
similar to how
Typescript
provides it for
jsx
?? I feel like this is so hugely required especially for large projects
s
You can get some of the way by making the props a real kotlin class ie.
class UserProps(val name: String, val photo: String? = null)
a
And with the current API, how does the user of my react components use this UserProp class??
s
Not sure. I did it for an old version by looking at how the existing functions work and hacked something together. Not sure if there is anything standard now
a
The current API can't enforce the use of those classes right now
t
Isn’t there a way to provide compile time safety for
kotlin-react
similar to how
Typescript
provides it for
jsx
?
It’s common problem of DSL with required options/properties
a
For now I am resorting to extending
ChildrenBuilder
. Despite it not being a true react component, it does work for most (Not all) our use case Something like this if any one asks
Copy code
private val User = FC<UserProps> {}

inline ChildrenBuilder.User(name: String, photo: String?=null) = User { 
  this.name=name
  this.photo = photo
}
t
We can’t say “goodbye extensions” 😞
a
Looks like we can't hence we need a compiler plugin for this 😀
t
Or sugar for DSL builders
m
Maybe it would be possible to make a Lint check for it? I still see a need for end-to-end tests (using Cypress for this at the moment), so anything that doesn't get caught at compilation will be caught in the end
a
How would DSL sugar look like in this case? syntactically I mean