The TypeScript problem is not aware of these type definitions.
Quick method
,
typings.d.ts :
interface String {
trimWhiteSpaces: () => string;
}
, . , , prototypes.js
TypeScript .
Pro-
TypeScript / . , , , .
- ( ), - :
: string-prototypes.ts
String.prototype.trimWhiteSpaces = trimWhiteSpaces;
interface String {
trimWhiteSpaces: typeof trimWhiteSpaces;
}
function trimWhiteSpaces() {
return this.split(' ').join('');
}
app.module.ts
:
import './string-prototypes';
, , , .
: string-helpers.ts
export function trimWhiteSpaces(input: string) {
return input.split(' ').join('');
}
:
import { trimWhiteSpaces } from './string-helpers';
-, , , .