You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
TypeScript does not understand x-if. Inside an x-if block, the passed variable should be evaluated for truthyiness, but it is not.
To Reproduce
Steps to reproduce the behavior:
The following code should do it:
typeMyNameProps={children: string}constMyName=({ children }: MyNameProps)=>(<div>{children}</div>)typeMyComponentProps={name: string|null}constMyComponent=({ name }: MyComponentProps)=>(<MyNamex-if={name}>{name}</MyName>)// ...
Expected behavior
TypeScript compiles successfully and does not show any errors. {name} gets passed as a string to <MyName>.
Actual behavior
TypeScript complains that <MyName> requires children to be of type string, but string | null was passed.
Environment
OS: Ubuntu 20.04
node version: 16.14.2
babel version: 7.9.0
version: 2.0.1
TypeScript version: 4.6.3
The text was updated successfully, but these errors were encountered:
@peakchen90 Of course it will, but the point is, sometimes the requirements are such that the type just needs to be nullable or optional. When that's the case, the following will work fine with TypeScript:
constMyComponent=({ name }: MyComponentProps)=>(<>
name && <MyName>{name}</MyName></>)
If this is okay with TypeScript, then x-if should also be okay.
Describe the bug
TypeScript does not understand x-if. Inside an
x-if
block, the passed variable should be evaluated for truthyiness, but it is not.To Reproduce
Steps to reproduce the behavior:
The following code should do it:
Expected behavior
TypeScript compiles successfully and does not show any errors.
{name}
gets passed as a string to<MyName>
.Actual behavior
TypeScript complains that
<MyName>
requireschildren
to be of typestring
, butstring | null
was passed.Environment
The text was updated successfully, but these errors were encountered: