-
Notifications
You must be signed in to change notification settings - Fork 22
$Refinement doesn't catch this case #78
Comments
Hi @volkanunsal, thanks for the detailed issue. Some observations:
getLayer(e: Object) {
const ret = PolyT = e.layer || e.target || e // <= const
return ret
} You might even use a type cast in this case getLayer(e: Object) {
return (e.layer || e.target || e: PolyT) // <= type cast
} or a typed return value getLayer(e: Object): PolyT { // <= return value
return e.layer || e.target || e
}
Make sure you added |
Also, since your predicate uses only type PolyT = L.Polyline | L.Polygon | L.Rectangle; |
@gcanti I tried, but I couldn't get the return type to work. Typecasting does work. Also here is my .babelrc file. I do have the {
"presets": ["es2015", "react", "stage-0"],
"passPerPreset": true,
"plugins": [
"tcomb",
"transform-decorators-legacy",
"transform-class-properties",
"syntax-flow",
"transform-flow-strip-types"
]
} Also, I'm getting const ret: PolyT = e.layer || e.target || e |
Oh, sorry, I didn't have
Maybe related to this issue. |
@gcanti I fixed the issue! The problem is if you use presets: ['stage-0', 'react', 'es2015'], |
Ah, thanks for explaining. I'll add that to the docs. p.s. |
I have the following type definition
And I use it this way:
As it will become clear, the type definition doesn't throw, even though the refinement function returns false.
The compiled assertion function for this is the following:
Also, it may be relevant that this function is defined twice in the compiled code. The same is true for the calls.
Btw, I just noticed that it looks like the refinement type is not asserted in the function body at all actually. That seems to be the real issue here.
The text was updated successfully, but these errors were encountered: