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

Incorrect typing for resolveId hook #2939

Closed
slavafomin opened this issue Jun 14, 2019 · 4 comments · Fixed by #2941
Closed

Incorrect typing for resolveId hook #2939

slavafomin opened this issue Jun 14, 2019 · 4 comments · Fixed by #2941

Comments

@slavafomin
Copy link

slavafomin commented Jun 14, 2019

Hello!

Thank you for this great tool!

However, right now, typing for the resolveId hook contradicts the documentation.

According to the docs:

Returning null defers to other resolveId functions and eventually the default resolution behavior...

However, in rollup.d.ts there is the following type:
export type ResolveIdResult = string | false | void | PartialResolvedId;

There is no null return value. This happend after I've updated the Rollup dependency to the latest version. Previously my code was working fine with returning null.

What exactly has changed? Should we update the documentation (and the behavior of all plugins) or the typing is just incorrect?

Thanks!

@slavafomin
Copy link
Author

According to my tests, it looks like the the typings are actually incorrect.

@lukastaegert
Copy link
Member

I must admit that I was under the impression that void is the same as null | undefined but this is not (no longer?) the case. Fix at #2941.

@slavafomin
Copy link
Author

In my opinion, the null value should be avoided at all if possible. It's somewhat strange falsy value, which type is object.

I would suggest to use the undefined instead. This is the default value for non-initialized variables and it's easy to define in TypeScript using question mark syntax.

The void type means a lack of value (this should be used only for functions which doesn't return value at all). In practice it's very similar to undefined though.

@lukastaegert
Copy link
Member

This is a religious debate. Others could argue that undefined is a variable that can even be redefined if you do it right which is why you should use null for explicitly declaring the absence of a value and explicit undefined comparisons should be avoided if possible. In any case, you always could use both interchangeably in the hooks and now the types reflect this. You are free to structure your code as you see fit.

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

Successfully merging a pull request may close this issue.

2 participants