babel-plugin-tcomb
babel-plugin-tcomb copied to clipboard
Nullable propery should not allow to skip property
https://yadi.sk/i/IMbvWSITyb5Hc
https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swo44AKADwC4wBvVMMagfnrYEEAnHgQwCeAHn7ZBAPlQBfAJT0Azvh6FsAc0bMwPAKb5MPUgCIAJjqj9MMfGCUr1RgNwz05Kg1b1sVmGDnO3SgZ-VxwCYlI3ACYaeiYWOjBuPiFRcSk5RWVVDXjtPQNjMwsrGzscpxcMChiPRO8YXxDooJCgA
Yes, babel-plugin-tcomb
is more permissive than Flow in this regard. Basically there is the following equivalence
{ a?: string } <=> { a: void | string }
Is this an issue in practice?
Is this an issue in practice?
Yes. Sorry for the translator, but I can not translate better. I use tcomb-validation for server response, null is fine on the server value is not specified and it sends null. The absence of the property-not the same thing, maybe it was someone renamed or on the server something is broken and I want to know about the problem at its very root, not in the form of a strange bug in the interface.
Original: Да. Извиняюсь за переводчик, но сам я переведу не лучше. Я использую tcomb для валидации ответа сервера, значение null -- это нормально, на сервере значение не задано и он присылает null. Отсутствие свойства -- не тоже самое, возможно оно было кем-то переименовано или на сервере что-то сломалось и я хочу знать о проблеме в самом её корне, а не в виде странного бага в интерфейсе.
I see. Currently there's no support in tcomb
(the library this plugin builds on) for optional fields (?
syntax). I wonder if your issue could be fixed by an explicit union
function foo2(x: { x: null | Array<any> }): string {
return 'default string'
}
@gcanti could you move this example into your docs? ( If you want I can make a PR ) under a section for "Multiple Types and OR Types" or something along those lines I feel it would be helpful to others as for my use case, I have an error handler that expects a string or an object, and this was what I needed to solve that problem. ( yes, this is not related to the OPs question directly, but the only resource for this question I had )
If you want I can make a PR
Ok, thanks
I will get to this this weekend I think... Cheers mate!