Skip to content

Return type of createRoot doesn't consider errors #1702

Open
@thetarnav

Description

@thetarnav

Describe the bug

After runWithOwner was changed to handle errors as any other effect would, its return type was changed to T | undefined as the returned value will always be undefined if the callback throws an error.
The new catchError does it the same way.
But createRoot doesn't, as far as typescript is concerned it will always return T, even though it behaves just like runWithOwner or catchError.
Is this intentional?
I know that handling T | undefined is a pain, and I find myself asserting it with ! quite often, but the lack of this indicator has made me believe that it could never return undefined.

Also, I guess that createMemo, mapArray, indexArray and others are in the same bucket, but changing all that would cause hell 🤣

Your Example Website or App

https://playground.solidjs.com/anonymous/d0665a89-4a79-4a81-b194-9916e96ac57a

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescriptrelating to typescript or types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions