-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
722 additions
and
59 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export type Data = { [key: string]: unknown } | ||
|
||
export type UnionToIntersection<U> = ( | ||
U extends any ? (k: U) => void : never | ||
) extends (k: infer I) => void | ||
? I | ||
: never | ||
|
||
// Conditional returns can enforce identical types. | ||
// See here: https://github.com/Microsoft/TypeScript/issues/27024#issuecomment-421529650 | ||
// prettier-ignore | ||
type Equal<Left, Right> = | ||
(<U>() => U extends Left ? 1 : 0) extends (<U>() => U extends Right ? 1 : 0) ? true : false; | ||
|
||
export type HasDefined<T> = Equal<T, unknown> extends true ? false : true |
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 |
---|---|---|
|
@@ -12,6 +12,6 @@ | |
"vue": ["../index.d.ts"] | ||
} | ||
}, | ||
"include": ["./*.d.ts", "*.ts"], | ||
"include": ["."], | ||
"compileOnSave": false | ||
} |
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { Vue } from './vue' | ||
import { VNode } from './vnode' | ||
import { ComponentOptions as Vue2ComponentOptions } from './options' | ||
import { EmitsOptions, SetupContext } from './v3-setup-context' | ||
import { Data } from './common' | ||
import { ComponentPropsOptions, ExtractPropTypes } from './v3-component-props' | ||
import { ComponentRenderProxy } from './v3-component-proxy' | ||
export { ComponentPropsOptions } from './v3-component-props' | ||
|
||
export type ComputedGetter<T> = (ctx?: any) => T | ||
export type ComputedSetter<T> = (v: T) => void | ||
|
||
export interface WritableComputedOptions<T> { | ||
get: ComputedGetter<T> | ||
set: ComputedSetter<T> | ||
} | ||
|
||
export type ComputedOptions = Record< | ||
string, | ||
ComputedGetter<any> | WritableComputedOptions<any> | ||
> | ||
|
||
export interface MethodOptions { | ||
[key: string]: Function | ||
} | ||
|
||
export type SetupFunction< | ||
Props, | ||
RawBindings = {}, | ||
Emits extends EmitsOptions = {} | ||
> = ( | ||
this: void, | ||
props: Readonly<Props>, | ||
ctx: SetupContext<Emits> | ||
) => RawBindings | (() => VNode | null) | void | ||
|
||
interface ComponentOptionsBase< | ||
Props, | ||
D = Data, | ||
C extends ComputedOptions = {}, | ||
M extends MethodOptions = {} | ||
> extends Omit< | ||
Vue2ComponentOptions<Vue, D, M, C, Props>, | ||
'data' | 'computed' | 'method' | 'setup' | 'props' | ||
> { | ||
// allow any custom options | ||
[key: string]: any | ||
|
||
// rewrite options api types | ||
data?: (this: Props & Vue, vm: Props) => D | ||
computed?: C | ||
methods?: M | ||
} | ||
|
||
export type ExtractComputedReturns<T extends any> = { | ||
[key in keyof T]: T[key] extends { get: (...args: any[]) => infer TReturn } | ||
? TReturn | ||
: T[key] extends (...args: any[]) => infer TReturn | ||
? TReturn | ||
: never | ||
} | ||
|
||
export type ComponentOptionsWithProps< | ||
PropsOptions = ComponentPropsOptions, | ||
RawBindings = Data, | ||
D = Data, | ||
C extends ComputedOptions = {}, | ||
M extends MethodOptions = {}, | ||
Mixin = {}, | ||
Extends = {}, | ||
Emits extends EmitsOptions = {}, | ||
EmitsNames extends string = string, | ||
Props = ExtractPropTypes<PropsOptions> | ||
> = ComponentOptionsBase<Props, D, C, M> & { | ||
props?: PropsOptions | ||
emits?: (Emits | EmitsNames[]) & ThisType<void> | ||
setup?: SetupFunction<Props, RawBindings, Emits> | ||
} & ThisType< | ||
ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits> | ||
> | ||
|
||
export type ComponentOptionsWithArrayProps< | ||
PropNames extends string = string, | ||
RawBindings = Data, | ||
D = Data, | ||
C extends ComputedOptions = {}, | ||
M extends MethodOptions = {}, | ||
Mixin = {}, | ||
Extends = {}, | ||
Emits extends EmitsOptions = {}, | ||
EmitsNames extends string = string, | ||
Props = Readonly<{ [key in PropNames]?: any }> | ||
> = ComponentOptionsBase<Props, D, C, M> & { | ||
props?: PropNames[] | ||
emits?: (Emits | EmitsNames[]) & ThisType<void> | ||
setup?: SetupFunction<Props, RawBindings, Emits> | ||
} & ThisType< | ||
ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits> | ||
> | ||
|
||
export type ComponentOptionsWithoutProps< | ||
Props = {}, | ||
RawBindings = Data, | ||
D = Data, | ||
C extends ComputedOptions = {}, | ||
M extends MethodOptions = {}, | ||
Mixin = {}, | ||
Extends = {}, | ||
Emits extends EmitsOptions = {}, | ||
EmitsNames extends string = string | ||
> = ComponentOptionsBase<Props, D, C, M> & { | ||
props?: undefined | ||
emits?: (Emits | EmitsNames[]) & ThisType<void> | ||
setup?: SetupFunction<Props, RawBindings, Emits> | ||
} & ThisType< | ||
ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits> | ||
> | ||
|
||
export type WithLegacyAPI<T, D, C, M, Props> = T & | ||
Omit<Vue2ComponentOptions<Vue, D, M, C, Props>, keyof T> |
Oops, something went wrong.