跳到主要内容

JavaScript

一、对象


1.1 对象结构赋值

type ObjectType = {
name:string;
age:number;
sex:string;
}
let {name,age}:ObjectType = {name:'哈哈哈',age:23,sex:'男'}
console.log(name)
console.log(age)

二、集合


2.1 Map

校验方式---赋初始元素
const map:Map<number,string> = new Map([
[1,'d'],
[2,'a]
]);
校验方式---通过 set 赋值新增元素
const map = new Map<string, object>();

map.set('abc', { name: '柏拉图' })
map.set('bcd', { age: 23 })

三、Window


  1. 单独管理 window 属性的校验: 创建 window.d.ts
/*
* @Description:
* @Author: 尹彬宇
* @Date: 2021-03-16 17:39:17
* @LastEditors: Please set LastEditors
* @LastEditTime: 2022-01-07 17:31:06
* @FilePath: /workbench/src/window.d.ts
*/
interface Omega {
trackEvent:function,
}

interface Window {
mappRequestPrefix: string;
PAGE_MAPP_CONFIG: {
id: string;
appId: string;
upmHost: string;
};
mappEnv: string;
mappRoutesConfig: {
base: string;
theme: {
logo: string;
banner: string;
};
};
__POWERED_BY_QIANKUN__?: string;
omega:Omega
}

四、Promise


4.1 Async 函数

type FuncType = () => Promise<boolean>;

const func: FuncType = async () => {
return true;
}

4.2 Promise 函数

type FuncType = () => Promise<boolean>;

const func: FuncType = () => {
return new Promise((resolve,reject) => {
resolve(true);
});
}