Skip to content

Commit

Permalink
wip(types): 调整 uesModel; 补充 ComponentInjectOption 类型推导
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Aug 9, 2024
1 parent c3148d2 commit 6ed207a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/dts-test/setupHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ describe('useModel', () => {
const r = useModel(props, 'foo')
expectType<Ref<any>>(r)

// @ts-expect-error
// fixed by xxxxxx
//// @ts-expect-error
useModel(props, 'bar')
},
})
Expand Down
6 changes: 4 additions & 2 deletions packages/runtime-core/src/apiDefineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type DefineComponent<
Props = ResolveProps<PropsOrPropOptions, E>,
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>,
S extends SlotsType = {},
I extends ComponentInjectOptions = {}, // fixed by xxxxxx
> = ComponentPublicInstanceConstructor<
CreateComponentPublicInstance<
Props,
Expand All @@ -68,7 +69,7 @@ export type DefineComponent<
PP & Props,
Defaults,
true,
{},
I,
S
>
> &
Expand Down Expand Up @@ -197,7 +198,8 @@ export function defineComponent<
PublicProps,
ResolveProps<Props, E>,
ExtractDefaultPropTypes<Props>,
S
S,
I // fixed by xxxxxx
>

// overload 3: object format with array props declaration
Expand Down
9 changes: 8 additions & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export { nextTick } from './scheduler'
export { defineComponent } from './apiDefineComponent'
export { defineAsyncComponent } from './apiAsyncComponent'
export { useAttrs, useSlots } from './apiSetupHelpers'
export { useModel } from './helpers/useModel'
// export { useModel } from './helpers/useModel' // fixed by xxxxxx

// <script setup> API ----------------------------------------------------------

Expand Down Expand Up @@ -456,3 +456,10 @@ export declare const withKeys: <T extends (event: KeyboardEvent) => any>(
},
modifiers: string[],
) => T

import type { ModelRef } from './apiSetupHelpers'
export declare function useModel<R>(
props: any,
name: string,
options?: any,
): ModelRef<R, string>

0 comments on commit 6ed207a

Please sign in to comment.