diff --git a/packages/runtime-core/__tests__/apiApp.spec.ts b/packages/runtime-core/__tests__/apiApp.spec.ts index d01ffb25..64899eba 100644 --- a/packages/runtime-core/__tests__/apiApp.spec.ts +++ b/packages/runtime-core/__tests__/apiApp.spec.ts @@ -124,10 +124,10 @@ describe('api: createApp', () => { }, setup() { // resolve in setup - const FooBar = resolveDirective('foo-bar') as any + const FooBar = resolveDirective('foo-bar')! return () => { // resolve in render - const BarBaz = resolveDirective('bar-baz') as any + const BarBaz = resolveDirective('bar-baz')! return applyDirectives(h('div'), [[FooBar], [BarBaz]]) } } diff --git a/packages/runtime-core/__tests__/apiCreateComponent.spec.tsx b/packages/runtime-core/__tests__/apiCreateComponent.spec.tsx index 978cd32a..c64eaa07 100644 --- a/packages/runtime-core/__tests__/apiCreateComponent.spec.tsx +++ b/packages/runtime-core/__tests__/apiCreateComponent.spec.tsx @@ -22,10 +22,17 @@ test('createComponent type inference', () => { default: 'hello' }, // explicit type casting - cc: (Array as any) as PropType, + cc: Array as PropType, // required + type casting dd: { - type: (Array as any) as PropType, + type: Array as PropType, + required: true + }, + // explicit type casting with constructor + ccc: Array as () => string[], + // required + contructor type casting + ddd: { + type: Array as () => string[], required: true } } as const, // required to narrow for conditional check @@ -60,7 +67,7 @@ test('createComponent type inference', () => { } }) // test TSX props inference - ;() + ;() }) test('type inference w/ optional props declaration', () => { diff --git a/packages/runtime-core/__tests__/apiSetupContext.spec.ts b/packages/runtime-core/__tests__/apiSetupContext.spec.ts index fd9c8ab7..d0602fc9 100644 --- a/packages/runtime-core/__tests__/apiSetupContext.spec.ts +++ b/packages/runtime-core/__tests__/apiSetupContext.spec.ts @@ -74,6 +74,39 @@ describe('api: setup context', () => { expect(dummy).toBe(1) }) + it('setup props should resolve the correct types from props object', async () => { + const count = ref(0) + let dummy + + const Parent = { + render: () => h(Child, { count: count.value }) + } + + const Child = createComponent({ + props: { + count: Number + }, + + setup(props) { + watch(() => { + dummy = props.count + }) + return () => h('div', props.count) + } + }) + + const root = nodeOps.createElement('div') + render(h(Parent), root) + expect(serializeInner(root)).toMatch(`
0
`) + expect(dummy).toBe(0) + + // props should be reactive + count.value++ + await nextTick() + expect(serializeInner(root)).toMatch(`
1
`) + expect(dummy).toBe(1) + }) + it('context.attrs', async () => { const toggle = ref(true) diff --git a/packages/runtime-core/__tests__/rendererSuspense.spec.ts b/packages/runtime-core/__tests__/rendererSuspense.spec.ts index 78221da4..62e50017 100644 --- a/packages/runtime-core/__tests__/rendererSuspense.spec.ts +++ b/packages/runtime-core/__tests__/rendererSuspense.spec.ts @@ -517,7 +517,7 @@ describe('renderer: suspense', () => { const Comp = { setup() { - const error = ref(null) + const error = ref(null) onErrorCaptured(e => { error.value = e return true