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
{{ message }}
Repository navigation
never cannot be spread into object, but it can be spread into JSX propsΒ #48556
As seen in kiliman/remix-params-helper#19, never is able to be spread into JSX props, even though never cannot be spread into objects. This seems odd to me as both compile to Object.assign. See screenshots:
TypeScript prevents spreading never into an object:
But spreading never into props works fine:
π Expected behavior
never should be prevented from spreading into jsx props, just like it cannot be spread into objects.
I wish spreading never is allowedβif anything it should be allowed in objects as well.
never extends object or any object type, so from a soundness perspective, I don't think this is unsafe. If it is compiled to Object.assign({}, obj), then obj being never is also fine because it's simply a top-type in parameter. From an ergonomics perspective, I often use ...(props as never) in cases where TS can't reason the type properly, like a simple polymorphic component:
The never here reads well to me because props can be naturally seen as function parameters in the context of functional components. If never is disallowed here, I'd have to do (props as any), which is undesirable because (a) it's less safe (though not so much) compared to never and (b) it's banned by ESLint for good reason and I don't want to disable it for this particular case.
Activity
Josh-Cena commentedon Apr 15, 2022
I wish spreading
neveris allowedβif anything it should be allowed in objects as well.neverextendsobjector any object type, so from a soundness perspective, I don't think this is unsafe. If it is compiled toObject.assign({}, obj), thenobjbeingneveris also fine because it's simply a top-type in parameter. From an ergonomics perspective, I often use...(props as never)in cases where TS can't reason the type properly, like a simple polymorphic component:The
neverhere reads well to me because props can be naturally seen as function parameters in the context of functional components. Ifneveris disallowed here, I'd have to do(props as any), which is undesirable because (a) it's less safe (though not so much) compared toneverand (b) it's banned by ESLint for good reason and I don't want to disable it for this particular case.