TypeScript

在Window下添加属性

declare global {
  interface Window {
		key: any
  }
}
1
2
3
4
5

忽视警告

注释会忽略下一行中产生的所有错误

// @ts-ignore

// eslint-disable-next-line to ignore the next line.

/* eslint-disable */ to ignore all warnings in a file.

1
2
3
4
5
6

使用[]避开检测

往一个第三方实例的prototype属性上添加自定义的属性和方法

这样用会报错:

Object.prototype.attribute = 'value'  // Property 'attribute' does not exist on type 'Object'.
1

这样用可以通过:

Object.prototype['attribute'] = 'value'
1
Last Updated: 2023/1/28 16:25:34
Contributors: 黎聪, licong96