Skip to content

Commit 3d22979

Browse files
committed
feat(types): support vue2 type
1 parent 23c9c32 commit 3d22979

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
lines changed

demi/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type { Plugin, App } from "vue";

demi/postinstall.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// reference vue-demi
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
let vuemodule = undefined;
7+
8+
try {
9+
vuemodule = require("vue");
10+
} catch (error) {}
11+
12+
if (vuemodule && /^2\.7/.test(vuemodule.version)) {
13+
const dir = path.resolve(__dirname);
14+
const v2file = path.join(dir, "vue2.d.ts");
15+
const index = path.join(dir, "index.d.ts");
16+
const content = fs.readFileSync(v2file, "utf-8");
17+
try {
18+
fs.unlinkSync(index);
19+
} catch (error) {}
20+
fs.writeFileSync(index, content, "utf-8");
21+
}

demi/vue2.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @ts-ignore
2+
import type { PluginFunction, PluginObject } from "vue";
3+
export declare type Plugin<T> = PluginObject<any> | PluginFunction<any>;
4+
5+
export type App<T = any> = any;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --ignore-path .gitignore",
1515
"lint:fix": "yarn lint --fix",
1616
"format": "prettier --write '**/*' --config ./.prettierrc",
17+
"postinstall": "node ./demi/postinstall.js",
1718
"prepare": "yarn build"
1819
},
1920
"author": "wangcch <[email protected]>",

src/context.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import type { App, InjectionKey } from "vue";
1+
import type { InjectionKey } from "vue";
22
import { getCurrentInstance, inject } from "vue";
33

44
import type { AxiosInstance } from "axios";
55
import axios from "axios";
66

7+
import type { App } from "../demi";
8+
79
const INJECT_INSIDE_WARN_MSG =
810
"[@axios-use/vue warn]: getUseRequestConfig() can only be used inside setup() or functional components.";
911

src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Plugin } from "vue";
1+
import type { Plugin } from "../demi";
22

33
import type { RequestConfigType } from "./context";
44
import { setUseRequestConfig } from "./context";

0 commit comments

Comments
 (0)