Skip to content

Commit

Permalink
fix: reduce meta type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed May 11, 2020
1 parent 5281e66 commit fa9efa3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default [
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
// 'prop-types',
],
plugins: [
typescript({
Expand Down
14 changes: 7 additions & 7 deletions src/meta.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MetaInfo } from 'vue-meta'
import defu from 'defu'
import { getCurrentInstance, toRefs, reactive } from '@vue/composition-api'
import { UnwrapRef, Ref } from '@vue/composition-api/dist/reactivity'
import { getCurrentInstance, toRefs, Ref, reactive } from '@vue/composition-api'
import { UnwrapRef } from '@vue/composition-api/dist/reactivity'

export type ReactiveHead<T = {}> = UnwrapRef<Ref<MetaInfo & T>>

Expand Down Expand Up @@ -51,6 +51,10 @@ export const getHeadOptions = (options: any) => {
return { _head, head }
}

type ToRefs<T extends Record<string, any>> = {
[P in keyof T]: Ref<T[P]>
}

export const useMeta = <T extends MetaInfo>(init?: T) => {
const vm = getCurrentInstance()
if (!vm) throw new Error('useMeta must be called within a component.')
Expand All @@ -64,9 +68,5 @@ export const useMeta = <T extends MetaInfo>(init?: T) => {

Object.assign(_head, createEmptyMeta())
Object.assign(_head, init || {})
return toRefs(
_head as UnwrapRef<
Ref<Exclude<ReturnType<typeof createEmptyMeta>, keyof T> & T>
>
)
return toRefs(_head) as ToRefs<ReturnType<typeof createEmptyMeta> & T>
}

0 comments on commit fa9efa3

Please sign in to comment.