From 7cdf1e50161f8d5d8b44adc54e83015d982ff642 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 3 Nov 2020 02:35:41 +0800 Subject: [PATCH] fix(types): allow any custom options for defineComponent, fix #579 (#584) --- src/component/componentOptions.ts | 4 ++++ test/types/defineComponent.spec.ts | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/component/componentOptions.ts b/src/component/componentOptions.ts index d31b6153..5f0f1508 100644 --- a/src/component/componentOptions.ts +++ b/src/component/componentOptions.ts @@ -45,6 +45,10 @@ interface ComponentOptionsBase< Vue2ComponentOptions, 'data' | 'computed' | 'method' | 'setup' | 'props' > { + // allow any custom options + [key: string]: any + + // rewrite options api types data?: (this: Props & Vue, vm: Props) => D computed?: C methods?: M diff --git a/test/types/defineComponent.spec.ts b/test/types/defineComponent.spec.ts index 709fda70..b08ef9bc 100644 --- a/test/types/defineComponent.spec.ts +++ b/test/types/defineComponent.spec.ts @@ -1,10 +1,4 @@ -import { - defineComponent, - h, - ref, - SetupContext, - PropType, -} from '../../src' +import { defineComponent, h, ref, SetupContext, PropType } from '../../src' import Router from 'vue-router' const Vue = require('vue/dist/vue.common.js') @@ -167,6 +161,14 @@ describe('defineComponent', () => { expect.assertions(2) }) + it('should any custom options', () => { + const App = defineComponent({ + foo: 'foo', + bar: 'bar', + }) + new Vue(App) + }) + it('infer the required prop', () => { const App = defineComponent({ props: {