Skip to content

Commit 9f92871

Browse files
committed
types(runtime-core): argument for props validator
Unfortunately it requires explicit annotation for now
1 parent a88895b commit 9f92871

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/runtime-core/src/componentProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type ComponentObjectPropsOptions<P = Data> = {
4242

4343
export type Prop<T, D = T> = PropOptions<T, D> | PropType<T>
4444

45-
type DefaultFactory<T> = () => T | null | undefined
45+
type DefaultFactory<T> = (props: Data) => T | null | undefined
4646

4747
interface PropOptions<T = any, D = T> {
4848
type?: PropType<T> | true | null

test-dts/defineComponent.test-d.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('with object props', () => {
1818
b: string
1919
e?: Function
2020
bb: string
21+
bbb: string
2122
cc?: string[] | undefined
2223
dd: { n: 1 }
2324
ee?: () => string
@@ -46,6 +47,11 @@ describe('with object props', () => {
4647
bb: {
4748
default: 'hello'
4849
},
50+
bbb: {
51+
// Note: default function value requires arrow syntax + explicit
52+
// annotation
53+
default: (props: any) => (props.bb as string) || 'foo'
54+
},
4955
// explicit type casting
5056
cc: Array as PropType<string[]>,
5157
// required + type casting
@@ -85,6 +91,7 @@ describe('with object props', () => {
8591
},
8692
validated: {
8793
type: String,
94+
// validator requires explicit annotation
8895
validator: (val: unknown) => val !== ''
8996
}
9097
},
@@ -94,6 +101,7 @@ describe('with object props', () => {
94101
expectType<ExpectedProps['b']>(props.b)
95102
expectType<ExpectedProps['e']>(props.e)
96103
expectType<ExpectedProps['bb']>(props.bb)
104+
expectType<ExpectedProps['bbb']>(props.bbb)
97105
expectType<ExpectedProps['cc']>(props.cc)
98106
expectType<ExpectedProps['dd']>(props.dd)
99107
expectType<ExpectedProps['ee']>(props.ee)

0 commit comments

Comments
 (0)