declare global。这对于为未提供类型定义的第三方库补充类型非常有用。import JSEncrypt from 'jsencrypt'
const encrypt = new JSEncrypt()
encrypt.setPublicKey('publicKey')
encrypt.encrypt('hello')
declare global {
interface JSEncrypt {
setPublicKey: (publicKey: string) => void
setPrivateKey: (privateKey: string) => void
encrypt: (value: string) => string
decrypt: (value: string) => string
getPublicKey: () => string
getPrivateKey: () => string
}
}
Element Plus 或 Ant Design Vue 的组件),可以在 tsconfig.json 中通过 types 字段指定全局组件类型定义文件的位置。{
"compilerOptions": {
"types": [
"element-plus/global",
"ant-design-vue/typings/global"
]
}
}