Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cb type should expect error as Error | undefined #25

Open
blumamir opened this issue Jun 14, 2022 · 0 comments
Open

cb type should expect error as Error | undefined #25

blumamir opened this issue Jun 14, 2022 · 0 comments

Comments

@blumamir
Copy link

Current type for load function's cb is:

export type INodeStyleCallBack<SuccessArg> = (err: Error, result?: SuccessArg) => void;

But the err can also be null to indicate that the callback has no errors. If trying to invoke the callback with null or undefined, typescript complains with:

Argument of type 'null' is not assignable to parameter of type 'Error'.ts(2345)

I think the type should be

export type INodeStyleCallBack<SuccessArg> = (err: Error | null, result?: SuccessArg) => void;

See for example in node types package:

    export function open(path: PathLike, flags: OpenMode | undefined, mode: Mode | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant