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

refactor: improve types #4667

Merged
merged 1 commit into from Oct 12, 2022
Merged

refactor: improve types #4667

merged 1 commit into from Oct 12, 2022

Conversation

sxzz
Copy link
Contributor

@sxzz sxzz commented Oct 12, 2022

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

Enhance types of internal functions, stricter.

@sxzz
Copy link
Contributor Author

sxzz commented Oct 12, 2022

@codecov
Copy link

codecov bot commented Oct 12, 2022

Codecov Report

Merging #4667 (2cd31de) into master (3cb7f13) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #4667      +/-   ##
==========================================
- Coverage   99.05%   99.05%   -0.01%     
==========================================
  Files         214      214              
  Lines        7549     7548       -1     
  Branches     2093     2092       -1     
==========================================
- Hits         7478     7477       -1     
  Misses         23       23              
  Partials       48       48              
Impacted Files Coverage Δ
src/utils/options/normalizeInputOptions.ts 100.00% <ø> (ø)
src/utils/options/options.ts 100.00% <ø> (ø)
src/rollup/rollup.ts 100.00% <100.00%> (ø)
src/utils/options/mergeOptions.ts 100.00% <100.00%> (ø)
src/utils/options/normalizeOutputOptions.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@lukastaegert
Copy link
Member

No, this is by design. rawOptions are stuff users write in their config files, and we first need to figure out, if that is even valid. The alternative is just throwing unhelpful runtime errors.

@sxzz
Copy link
Contributor Author

sxzz commented Oct 12, 2022

I see, but does it really help? I didn't change the runtime code actually, but removed type assertions as. It will warnUnknownOptions as like as before too.

@sxzz
Copy link
Contributor Author

sxzz commented Oct 12, 2022

It will cause a pretty serious problem: when refactoring code, I can not find all the places that referenced types by TypeScript. #4668 is the example.

@lukastaegert
Copy link
Member

I see, but does it really help

I guess it does not 🙄
So yes, your changes do make some sense

@sxzz
Copy link
Contributor Author

sxzz commented Oct 12, 2022

Checking the configuration by TS type obviously doesn't work. A better way is to check it in normalize function. If the configuration is invalid, an exception needs to be thrown to avoid runtime errors.

We can see this here, await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions)) is GenericConfigObject, and it just passed to normalizeInputOptions with implicit converted to InputOptions. For example: if onwarn option is not a function, it will still apply this, and cause a runtime error.

rollup/src/rollup/rollup.ts

Lines 128 to 130 in 3cb7f13

const { options, unsetOptions } = normalizeInputOptions(
await rawPlugins.reduce(applyOptionHook(watchMode), Promise.resolve(rawInputOptions))
);

@lukastaegert lukastaegert merged commit fec5132 into rollup:master Oct 12, 2022
@sxzz sxzz deleted the refactor/types branch October 12, 2022 17:10
@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.2.0. You can test it via npm install rollup.

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 this pull request may close these issues.

None yet

3 participants