-
-
Notifications
You must be signed in to change notification settings - Fork 9k
types(runtime-core): enable plugin option types #3969
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
Merged
yyx990803
merged 7 commits into
vuejs:main
from
tony19-contrib:feat/types/plugin-options
Nov 14, 2022
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
47dbc22
types(runtime-core): enable plugin option types
tony19 e2dc246
types(runtime-core): add d.ts tests for app.use()
tony19 c9c7e0a
remove unnecessary rest parameter
tony19 6139f60
add test for passing multiple plugin options
tony19 863031c
refactor: stricter plugin types
posva 5557c64
Merge pull request #1 from vuejs/feat/types/plugin-options
tony19 bda19de
remove unnecessary typing from plugin install fn type
tony19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { createApp } from './index' | ||
|
|
||
| type App = ReturnType<typeof createApp> | ||
|
|
||
| type PluginAOptionType = { | ||
| option1?: string | ||
| option2: number | ||
| option3: boolean | ||
| } | ||
|
|
||
| const PluginA = { | ||
| install(app: App, ...options: PluginAOptionType[]) { | ||
| options[0].option1 | ||
| options[0].option2 | ||
| options[0].option3 | ||
| } | ||
| } | ||
|
|
||
| const PluginB = { | ||
| install(app: App) {} | ||
| } | ||
|
|
||
| const PluginC = (app: App, ...options: string[]) => {} | ||
|
|
||
| createApp({}) | ||
| .use(PluginA) | ||
| // @ts-expect-error option2 and option3 (required) missing | ||
| .use(PluginA, {}) | ||
| // @ts-expect-error type mismatch | ||
| .use(PluginA, true) | ||
| // @ts-expect-error type mismatch | ||
| .use(PluginA, undefined) | ||
| // @ts-expect-error type mismatch | ||
| .use(PluginA, null) | ||
| // @ts-expect-error type mismatch | ||
| .use(PluginA, 'foo') | ||
| // @ts-expect-error type mismatch | ||
| .use(PluginA, 1) | ||
| .use(PluginA, { option2: 1, option3: true }) | ||
| .use(PluginA, { option1: 'foo', option2: 1, option3: true }) | ||
| .use(PluginA, { option1: 'foo', option2: 1, option3: true }, { option2: 1, option3: true }) | ||
posva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // @ts-expect-error option2 (required) missing | ||
| .use(PluginA, { option3: true }) | ||
|
|
||
| .use(PluginB) | ||
| // @ts-expect-error unexpected plugin option | ||
| .use(PluginB, {}) | ||
| // @ts-expect-error unexpected plugin option | ||
| .use(PluginB, true) | ||
| // @ts-expect-error unexpected plugin option | ||
| .use(PluginB, undefined) | ||
| // @ts-expect-error unexpected plugin option | ||
| .use(PluginB, null) | ||
| // @ts-expect-error type mismatch | ||
| .use(PluginB, 'foo') | ||
| // @ts-expect-error type mismatch | ||
| .use(PluginB, 1) | ||
|
|
||
| .use(PluginC) | ||
posva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // @ts-expect-error unexpected plugin option | ||
| .use(PluginC, {}) | ||
| // @ts-expect-error unexpected plugin option | ||
| .use(PluginC, true) | ||
| // @ts-expect-error unexpected plugin option | ||
| .use(PluginC, undefined) | ||
| // @ts-expect-error unexpected plugin option | ||
| .use(PluginC, null) | ||
| .use(PluginC, 'foo') | ||
| // @ts-expect-error type mismatch | ||
| .use(PluginC, 1) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.