cash.js库提供TypeScript声明cash.d.ts
我尝试在client.ts
文件中使用它,但效果不佳:
/// <reference path="./cash.d.ts"/>
const $: Cash = (window as any).$
$('div') // compilation error
尝试了另一个版本:
/// <reference path="./cash.d.ts"/>
const $: CashStatic = (window as any).$
$('div') // compilation error
最后,我使用了这个有效的技巧:
/// <reference path="./cash.d.ts"/>
const $: (arg: string) => Cash = (window as any).$
$('div')
它奏效了,但是我想知道使用它的正确方法是什么?
答案 0 :(得分:0)
最后,在检查了源代码之后,我发现了如何做
const $ = (window as any).$ as typeof Cash.prototype.init & CashStatic