-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2698 from PrefectHQ/dependabot/npm_and_yarn/vue-t…
…sc-2.1.4 Bump vue-tsc from 2.0.29 to 2.1.4
- Loading branch information
Showing
6 changed files
with
65 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,34 +1,40 @@ | ||
export type Component = { $props: unknown } | ||
export type ComponentDefinition = { new(...args: unknown[]): Component } | ||
import { AsyncComponentLoader, Component, FunctionalComponent } from 'vue' | ||
|
||
// https://stackoverflow.com/questions/73732549/narrow-number-argument-of-function-to-be-literal-type?noredirect=1#comment130199140_73732549 | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
type NoInfer<T> = T & {} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
type Constructor = new (...args: any) => any | ||
|
||
type WithPropsArgs<T extends ComponentDefinition, E extends string = '', P = InstanceType<T>['$props']> = Omit<Partial<P>, E> extends Omit<P, E> | ||
export type ComponentProps<TComponent extends Component> = TComponent extends Constructor | ||
? InstanceType<TComponent>['$props'] | ||
: TComponent extends AsyncComponentLoader<infer T extends Component> | ||
? ComponentProps<T> | ||
: TComponent extends FunctionalComponent<infer T> | ||
? T | ||
: never | ||
|
||
type WithPropsArgs<T extends Component, E extends string = '', P = ComponentProps<T>> = Omit<Partial<P>, E> extends Omit<P, E> | ||
? [ component: T, props?: Omit<P, E> & Record<string, unknown> ] | ||
: [ component: T, props: Omit<P, E> & Record<string, unknown> ] | ||
|
||
type WithProps<T extends ComponentDefinition, E extends string = '', P = InstanceType<T>['$props']> = Omit<Partial<P>, E> extends Omit<P, E> | ||
type WithProps<T extends Component, E extends string = '', P = ComponentProps<T>> = Omit<Partial<P>, E> extends Omit<P, E> | ||
? { component: T, props?: Omit<P, E> & Record<string, unknown> } | ||
: { component: T, props: Omit<P, E> & Record<string, unknown> } | ||
|
||
export function withProps<T extends ComponentDefinition>(...[component, props]: WithPropsArgs<T>): WithProps<NoInfer<T>> { | ||
export function withProps<T extends Component>(...[component, props]: WithPropsArgs<T>): WithProps<T> { | ||
return { | ||
component, | ||
props, | ||
} | ||
} as WithProps<T> | ||
} | ||
|
||
export function withPropsWithoutExcluded<T extends ComponentDefinition, E extends string>(excluded: E | E[], ...[component, props]: WithPropsArgs<T, E>): WithProps<NoInfer<T>, E> { | ||
export function withPropsWithoutExcluded<T extends Component, E extends string>(excluded: E | E[], ...[component, props]: WithPropsArgs<T, E>): WithProps<T, E> { | ||
return { | ||
component, | ||
props, | ||
} | ||
} as WithProps<T, E> | ||
} | ||
|
||
export function withPropsWithoutExcludedFactory<E extends string>(prop: E | E[]) { | ||
return function<T extends ComponentDefinition>(...args: WithPropsArgs<T, E>): WithProps<T, E> { | ||
return function<T extends Component>(...args: WithPropsArgs<T, E>): WithProps<T, E> { | ||
return withPropsWithoutExcluded(prop, ...args) | ||
} | ||
} |