Custom Prop that is Optional #307
Unanswered
mashaalmemon
asked this question in
Q&A
Replies: 2 comments 2 replies
-
|
null and undefined are handled by default in all transforms, so you don't need to write code for those. if you want a default value just provide one as parameter to prop / tProp (in this case a number) as you would if your prop would be a plain number with a default |
Beta Was this translation helpful? Give feedback.
2 replies
-
|
in other words, where the transform is oblivious to null and undefined should work |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
From a typing perspective I'm trying to setup an optional custom prop. Here I have a custom prop which takes
Momentand stores the date value as anumber:I've tried to setup something similar where
Momentis optional, but I can't get an optional custom prop to work. My transform has a basic signature like this:The prop would be setup like so if optional:
However, I get this typing error:
TS2345: Argument of type 'ModelPropTransform<number | undefined, Moment | undefined>' is not assignable to parameter of type 'ModelPropTransform<number, Moment | undefined>'. Type 'number | undefined' is not assignable to type 'number'. Type 'undefined' is not assignable to type 'number'.Any guidance you can give would be helpful.
Beta Was this translation helpful? Give feedback.
All reactions