10000 fix(type): fix tying issues in #428 by antfu · Pull Request #444 · vuejs/composition-api · GitHub
[go: up one dir, main page]

Skip to content

fix(type): fix tying issues in #428 #444

8000 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
merged 2 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(type): fix tying issues in #428
  • Loading branch information
antfu committed Jul 18, 2020
commit ef20b4a05c423c30acad1557aa9eb376bedff9d9
26 changes: 8 additions & 18 deletions src/component/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,17 @@ type OptionalKeys<T, MakeDefaultRequired> = Exclude<
RequiredKeys<T, MakeDefaultRequired>
>

type ExtractFunctionPropType<
T extends Function,
TArgs extends Array<any> = any[],
TResult = any
> = T extends (...args: TArgs) => TResult ? T : never

type ExtractCorrectPropType<T> = T extends Function
? ExtractFunctionPropType<T>
: Exclude<T, Function>

// prettier-ignore
type InferPropType<T> = T extends null
? any // null & true would fail to infer
: T extends { type: null | true }
? any // As TS issue https://github.com/Microsoft/TypeScript/issues/14829 // somehow `ObjectConstructor` when inferred from { (): T } becomes `any` // `BooleanConstructor` when inferred from PropConstructor(with PropMethod) becomes `Boolean`
: T extends ObjectConstructor | { type: ObjectConstructor }
? { [key: string]: any }
: T extends BooleanConstructor | { type: BooleanConstructor }
? boolean
: T extends Prop<infer V>
? ExtractCorrectPropType<V> : T;
? any // As TS issue https://github.com/Microsoft/TypeScript/issues/14829 // somehow `ObjectConstructor` when inferred from { (): T } becomes `any` // `BooleanConstructor` when inferred from PropConstructor(with PropMethod) becomes `Boolean`
: T extends ObjectConstructor | { type: ObjectConstructor }
? { [key: string]: any }
: T extends BooleanConstructor | { type: BooleanConstructor }
? boolean
: T extends Prop<infer V>
? V
: T

export type ExtractPropTypes<
O,
Expand Down
7 changes: 1 addition & 6 deletions src/component/componentProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,12 @@ export type ComponentRenderProxy<
$data: D
$props: Readonly<P & PublicProps>
$attrs: Data
$refs: Data
$slots: Data
$root: ComponentInstance | null
$parent: ComponentInstance | null
$emit: (event: string, ...args: unknown[]) => void
} & Readonly<P> &
UnwrapRef<B> &
D &
M &
ExtractComputedReturns<C> &
Vue
Omit<Vue, '$data' | '$props' | '$attrs'>

// for Vetur and TSX support
type VueConstructorProxy<PropsOptions, RawBindings> = VueConstructor & {
Expand Down
0