From 92d913413b0c07c66c96f68dcdfac6c92b803ee0 Mon Sep 17 00:00:00 2001 From: Raiondesu Date: Fri, 9 Feb 2018 17:45:02 +0300 Subject: [PATCH] Finally solved the types. --- README.md | 16 ++++++++++++++++ package.json | 4 +++- types/index.d.ts | 13 +------------ types/tsconfig.json | 17 +++++++++++++++++ types/vue.d.ts | 4 ++-- 5 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 types/tsconfig.json diff --git a/README.md b/README.md index a247606..f6d0113 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ - [How do I populate `metaInfo` from the result of an asynchronous action?](#how-do-i-populate-metainfo-from-the-result-of-an-asynchronous-action) - [Why doesn't `vue-meta` support `jsnext:main`?](#why-doesnt-vue-meta-support-jsnextmain) - [Examples](#examples) +- [TypeScript Support](#typescript-support) @@ -794,3 +795,18 @@ If this were not the case, you would have to instruct Babel to convert `default` # Examples To run the examples; clone this repository & run `npm install` in the root directory, and then run `npm run dev`. Head to http://localhost:8080. + +# TypeScript Support + +If you have problems with types using vue-meta, then you're most probably using vue-class-component. +In any troublesome situation, just add the following ambient declaration to your types: + +```js +import { MetaInfo } from 'vue-meta'; + +declare module "vue/types/vue" { + interface Vue { + metaInfo?: MetaInfo | (() => MetaInfo) + } +} +``` diff --git a/package.json b/package.json index 41417b4..9b4d5d6 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,9 @@ }, "files": [ "lib", - "yarn.lock" + "yarn.lock", + "types/index.d.ts", + "types/vue.d.ts" ], "homepage": "https://github.com/declandewet/vue-meta", "keywords": [ diff --git a/types/index.d.ts b/types/index.d.ts index 01fffcb..8c7920d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -33,18 +33,7 @@ export interface MetaInfo { charset?: string, content?: string, 'http-equiv'?: 'content-security-policy' | 'refresh', - name?: 'application-name' - | 'author' - | 'description' - | 'generator' - | 'keywords' - | 'referrer' - | 'creator' - | 'googlebot' - | 'publisher' - | 'robots' - | 'slurp' - | 'viewport', + name?: string, [key: string]: any }[] diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..b41cee0 --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "es2015", + "moduleResolution": "node", + "lib": [ + "es5", + "dom", + "es2015.promise" + ], + "strict": true, + "noEmit": true + }, + "include": [ + "*.d.ts" + ] +} diff --git a/types/vue.d.ts b/types/vue.d.ts index d05cb5e..fb449e7 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -7,12 +7,12 @@ import { MetaInfo } from './index'; declare module "vue/types/options" { interface ComponentOptions { - metaInfo?: MetaInfo | (() => MetaInfo); + metaInfo?: MetaInfo | (() => MetaInfo) } } declare module "vue/types/vue" { interface Vue { - metaInfo?: MetaInfo | (() => MetaInfo); + metaInfo?: MetaInfo | (() => MetaInfo) } }