-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
feat(cli,cli-service,cli-test-utils): add ts declaration #5356
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
Conversation
the data written by fs.writeFile should be any
compatible with esModuleInterop:false
The problem come from here
if I change code to import { Configuration as WebpackOptions } from 'webpack' // it will use @types/webpack
The key to the problem is which to use, |
revert yarn.lock, use registry.yarnpkg.com instead of registry.npmjs.org
1. rename GeneratorRootOptions to Preset. 2. fix wrong use of type object, use Record<string,any> instead. 3. support function type of plugin.
1. use @types/webpack instead of webpack/declarations. 2. add 'export {}' to the module to shut off automatic exporting. see https://stackoverflow.com/questions/52583603/intentional-that-export-shuts-off-automatic-export-of-all-symbols-from-a-ty. 3. add reference node, so @types/node can be included even typeRoots/types is specified.
Usage in *.jsmaybe it's worth mentioning in the documentation, vscode can provide completions in this way. service pluginindex.js /** @type {import('@vue/cli-service').ServicePlugin} */
module.exports = (api, options) => {
} generator plugingenerator/index.js /** @type {import('@vue/cli').GeneratorPlugin} */
module.exports = (api) => {
} project configvue.config.js /** @type {import('@vue/cli-service').ProjectOptions} */
module.exports = {
// options...
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the great help!
Please also fix the merge conflicts with the dev branch and I think we'll be good to go.
Co-authored-by: Haoqun Jiang <[email protected]>
since Function belongs to object, so a Function which return type is not object is still assignable to 'object | () => return type'. we need exclude Function from object. releated: microsoft/TypeScript#38254 https://stackoverflow.com/questions/24613955/is-there-a-type-in-typescript-for-anything-except-functions
resolve conflicts in package.json, yarn.lock
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
Other information:
for issue #5324 , I have added some ts declarations
GeneratorAPI
,PromptModuleAPI
in @vue/cliPluginAPI
in @vue/cli-serviceI added test for these declarations. Also I linted the code by
dtslint
with some necessary rules according to the README of DefinitelyTyped .test by
npx tsc -p packages/@vue/cli/types/tsconfig.json
known issue
It seems there are some problem in webpack's declaration. so
"skipLibCheck": true
should be set intsconfig.json
when usePluginAPI
in .ts.By the way, I formated and linted the codes whithout adding config file (like
tslint.json
,.prettierrc
) to vue-cli repo. Besides, vscode may report error for*.d.ts
caused by eslint parser of cli repo. I believe I should avoid adding extra config files/codes or changing eslintignore. Core maintaner do this will be better, if necessary.Add I used
yarn link
to verify the declarations of @vue/cli, @vue/cli-service, @vue/cli-test-utils in my own plugin repo.PluginAPI
andGeneratorAPI
can be used in .ts file normallyI hope this pr will be helpful.
appendix
We can organize the file structure better, but It may cause break change. Or there is good way I overlooked.