比如给axios的 AxiosRequestConfig 加一个属性:
创建一个 src/axios.d.ts 文件,内容为:
1 2 3 4 5 6 | import * as axios from 'axios'; declare module 'axios' { interface AxiosRequestConfig { hideErrorMessage?: boolean; } } |
Put additional typings in custom-typings.d.ts
in root of src
.
custom-typings.d.ts
1 2 3 4 5 6 7 8 9 10 11 12 | import * as mongoose from "mongoose"; //augment validate.js declare module "validate.js" { let Promise: any; function async(param: any): any; } //augment mongoose declare module "mongoose" { let modelSchemas: mongoose.Schema[] } |
my-module.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import validate = require("validate.js"); import mongoose = require("mongoose"); import * as Bluebird from "bluebird"; validate.Promise = Bluebird; mongoose.Promise = Bluebird; let schema = new mongoose.Schema({ name: String }); mongoose.modelSchemas = [schema]; validate.async("foo"); |
Why import
with ES5 syntax (require
)? ES6 modules and their properties are constant.