Square 付款表格对象的全球参考 Angular

Global Reference of Square payment form object into Angular

没有将 Square checkout form for Angular 4/5/6 so I'm trying to figure out what this might entail by creating a test component, but I can't figure out how to get a reference to their global object SqPaymentForm 实现到 Angular 并且 TypeScript 不会抛出一个错误,说它在 window 对象上不存在 window.SqPaymentForm 因为它确实存在。

任何人都可以指出如何让 TypeScript 识别 window.SqPaymentForm 存在的方向吗?

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [],
  providers: [
    { provide: 'SQUARE', useFactory: getSquare }
  ]
})
export class SquareModule { }

export function getSquare() {
  return (typeof window !== undefined) 
      // TypeScript indicates it doesn't exist on Window 
      ? window.SqPaymentForm 
      : null;
}

弄清楚我必须创建自己的打字,但无法弄清楚如何通过 .d.ts 加载它,所以现在,它在 Square 模块中声明:

declare global {
  interface Window {
    SqPaymentForm: any;
  }
}

或将 window.SqPaymentForm 替换为:

(<any>window).SqPaymentForm