Fix prop typing
This commit is contained in:
@@ -205,8 +205,15 @@ describe("origin-relative scene graph", () => {
|
||||
let xMounts = 0;
|
||||
let xUnmounts = 0;
|
||||
let yUnmounts = 0;
|
||||
|
||||
const X = defineComponent({
|
||||
name: "X",
|
||||
props: {
|
||||
message: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
setup() {
|
||||
onMounted(() => {
|
||||
xMounts += 1;
|
||||
@@ -214,6 +221,9 @@ describe("origin-relative scene graph", () => {
|
||||
onUnmounted(() => {
|
||||
xUnmounts += 1;
|
||||
});
|
||||
defineProps<{
|
||||
message: string;
|
||||
}>();
|
||||
return () =>
|
||||
h(
|
||||
"div",
|
||||
|
||||
@@ -24,6 +24,7 @@ import type {
|
||||
OriginSceneNode,
|
||||
OriginSceneNodeState,
|
||||
OriginView,
|
||||
PropsOf,
|
||||
} from "./types";
|
||||
|
||||
interface SceneNodeState {
|
||||
@@ -79,12 +80,12 @@ let viewSequence = 0;
|
||||
* ```
|
||||
*/
|
||||
export function originView<
|
||||
Props extends Record<string, unknown> = Record<string, unknown>,
|
||||
T extends Component = Component,
|
||||
>(
|
||||
component: Component,
|
||||
props?: Props,
|
||||
component: T,
|
||||
props?: PropsOf<T>,
|
||||
options: OriginViewOptions = {},
|
||||
): OriginView<Props> {
|
||||
): OriginView<T> {
|
||||
const inferredName =
|
||||
options.name ??
|
||||
(typeof component === "object" && "name" in component
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import type { Component, ComputedRef, CSSProperties, ShallowRef } from "vue";
|
||||
|
||||
export type PropsOf<T> =
|
||||
T extends abstract new (...args: any[]) => { $props: infer P }
|
||||
? P
|
||||
: T extends (props: infer P, ...args: any[]) => any
|
||||
? P
|
||||
: never;
|
||||
|
||||
/**
|
||||
* A view is a recipe for creating a Vue component, not a mounted instance.
|
||||
*
|
||||
@@ -9,12 +16,13 @@ import type { Component, ComputedRef, CSSProperties, ShallowRef } from "vue";
|
||||
* @typeParam Props - The props accepted by the component recipe.
|
||||
*/
|
||||
export interface OriginView<
|
||||
Props extends Record<string, unknown> = Record<string, unknown>,
|
||||
T extends Component = Component,
|
||||
// Props extends Record<string, unknown> = Record<string, unknown>,
|
||||
> {
|
||||
/** The Vue component definition that will be mounted for this recipe. */
|
||||
readonly component: Component;
|
||||
readonly component: T;
|
||||
/** Props passed to the component when the recipe is mounted. */
|
||||
readonly props?: Readonly<Props>;
|
||||
readonly props?: Readonly<PropsOf<T>>;
|
||||
/**
|
||||
* A developer-facing recipe identity used in diagnostics and as the prefix
|
||||
* of generated scene-node keys. It does not make Vue reuse an instance.
|
||||
|
||||
Reference in New Issue
Block a user