Приложение на ангуляре.
Я пытаюсь добавить метод к типу Number:
tsconfig.json:
...
"typeRoots": [
"node_modules/@types",
"types"
]
...
types/number.d.ts:
export {}
declare global {
interface Number {
isInt() : boolean
}
}
number.extension.ts:
Number.prototype.isInt = function() {
return (Math.round(this) == this)
}
И, при попытке компиляции, я получаю ошибки:
Error: number.extensions.ts:16:18 - error TS2339: Property 'isInt' does not exist on type 'Number'.
[ng] 16 Number.prototype.isInt = function() {
[ng] ~~~~~
[ng] Error: node_modules/typescript/lib/lib.es5.d.ts:395:5 - error TS2300: Duplicate identifier 'trimMiddle'.
[ng] 395 trimMiddle: () => any;
[ng] ~~~~~~~~~~
[ng] Error: node_modules/typescript/lib/lib.es5.d.ts:396:5 - error TS2411: Property 'anchor' of type '(name: string) => string' is not assignable to string index type '() => any'.
[ng] 396 [x: string]: () => any;
[ng] ~~~~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/typescript/lib/lib.es5.d.ts:396:5 - error TS2411: Property 'charAt' of type '(pos: number) => string' is not assignable to string index type '() => any'.
[ng] 396 [x: string]: () => any;
[ng] ~~~~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/typescript/lib/lib.es5.d.ts:396:5 - error TS2411: Property 'charCodeAt' of type '(index: number) => number' is not assignable to string index type '() => any'.
[ng] 396 [x: string]: () => any;