搞定tsnode执行问题。

This commit is contained in:
Kane Wang 2023-03-07 15:55:53 +08:00
parent 34c2922da7
commit 7454b97e65
6 changed files with 40 additions and 34 deletions

View File

@ -2,7 +2,6 @@
"name": "code_test",
"version": "1.0.0",
"description": "用于测试前端的typescript代码",
"main": "index.ts",
"type": "module",
"scripts": {
"test": "ts-node-esm index.ts"

View File

@ -1,14 +0,0 @@
/*
* @Author: Kane
* @Date: 2023-03-04 17:23:02
* @LastEditors: Kane
* @FilePath: /task_schedule/shims-vue.d.ts
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
*/
declare module '*.vue' {
import { ComponentOptions } from 'vue';
const componentOptions: ComponentOptions;
export default componentOptions;
}

View File

@ -9,31 +9,22 @@
*/
// 索引类型
interface Point
{
x: number;
y: number;
}
import { getProperty } from "@/utils/api/api.js";
type kes = keyof Point;
type name = "name";
const value: name = "name";
// 联合类型
interface Circle
{
radius: number;
area: number;
}
interface Rectangle
const circle: Circle =
{
area: number;
wdith: number;
height: number;
}
radius: 100,
area: 1000,
};
type Shape = Circle | Rectangle;
const kind = getProperty(circle, "area");
type kind2 = { [P in keyof Circle]: Circle[P] };
let a: Shape;
console.log(kind);
console.log(circle.area);

View File

@ -0,0 +1,16 @@
/*
* @Author: Kane
* @Date: 2023-03-07 11:21:38
* @LastEditors: Kane
* @FilePath: /ts-practice/src/utils/api/api.ts
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
*/
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K]
{
return obj[key];
}
export { getProperty };

View File

@ -16,3 +16,14 @@ service.interceptors.request.use(
return await Promise.reject(error);
}
);
service.interceptors.response.use(
(response) =>
{
return response;
},
async (error) =>
{
return await Promise.reject(error);
}
);

View File

@ -11,11 +11,14 @@
"compilerOptions": {
"strict": true,
"target": "ESNext",
"module": "CommonJS",
"module": "ESNext",
"esModuleInterop": true,
"moduleResolution": "nodenext",
"lib": [
"ESNext",
"DOM",
],
"outDir": "./dist",
"baseUrl": "./",
"paths": {
"@/*": [