Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: drop createComponent #398

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions src/component/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,43 +119,3 @@ export function defineComponent<
export function defineComponent(options: any) {
return options as any
}

// overload 1: object format with no props
export function createComponent<RawBindings>(
options: ComponentOptionsWithoutProps<unknown, RawBindings>
): VueProxy<unknown, RawBindings>
// overload 2: object format with array props declaration
// props inferred as { [key in PropNames]?: any }
// return type is for Vetur and TSX support
export function createComponent<
PropNames extends string,
RawBindings = Data,
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
>(
// prettier-ignore
options: (
ComponentOptionsWithArrayProps<PropNames, RawBindings>) &
Omit<Vue2ComponentOptions<Vue>, keyof ComponentOptionsWithProps<never, never>>
): VueProxy<Readonly<{ [key in PropNames]?: any }>, RawBindings>
// overload 3: object format with object props declaration
// see `ExtractPropTypes` in ./componentProps.ts
export function createComponent<
Props,
RawBindings = Data,
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
>(
// prettier-ignore
options: (
// prefer the provided Props, otherwise infer it from PropsOptions
HasDefined<Props> extends true
? ComponentOptionsWithProps<PropsOptions, RawBindings, Props>
: ComponentOptionsWithProps<PropsOptions, RawBindings>) &
Omit<Vue2ComponentOptions<Vue>, keyof ComponentOptionsWithProps<never, never>>
): VueProxy<PropsOptions, RawBindings>
// implementation, deferring to defineComponent, but logging a warning in dev mode
export function createComponent(options: any) {
if (__DEV__) {
Vue.util.warn('`createComponent` has been renamed to `defineComponent`.')
}
return defineComponent(options)
}
1 change: 0 additions & 1 deletion src/component/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export {
Data,
createComponent,
defineComponent,
SetupFunction,
SetupContext,
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default plugin
export { default as createElement } from './createElement'
export { SetupContext }
export {
createComponent,
defineComponent,
ComponentRenderProxy,
PropType,
Expand Down
35 changes: 0 additions & 35 deletions test/types/defineComponent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
createComponent,
defineComponent,
createElement as h,
ref,
Expand Down Expand Up @@ -217,38 +216,4 @@ describe('defineComponent', () => {
})
})
})

describe('retro-compatible with createComponent', () => {
it('should still work and warn', () => {
const warn = jest
.spyOn(global.console, 'error')
.mockImplementation(() => null)
const Child = createComponent({
props: { msg: String },
setup(props) {
return () => h('span', props.msg)
},
})

const App = createComponent({
setup() {
const msg = ref('hello')
return () =>
h('div', [
h(Child, {
props: {
msg: msg.value,
},
}),
])
},
})
const vm = new Vue(App).$mount()
expect(vm.$el.querySelector('span').textContent).toBe('hello')
expect(warn.mock.calls[0][0]).toMatch(
'[Vue warn]: `createComponent` has been renamed to `defineComponent`.'
)
warn.mockRestore()
})
})
})