我想在 TypeScript中使用我自己的全局类型(没有import
, using )。declare type
例如:
// File with global types.
declare type Function<TParameter, TResult> = (parameter: TParameter) => TResult
// Another file.
const someMethod = (callback: Function<number, string>) => { ... }
但是,由于或任何外部库而存在冲突(TS2300: Duplicate identifier 'Function'.
) 。lib.es5.d.ts
有没有办法忽略现有的Function
声明并使用我自己的?
我知道的唯一解决方案是将所有自己的类型放入命名空间:
// File with global types
declare type MyTypes.Function<TParameter, TResult> = (parameter: TParameter) => TResult
// Another file.
const someMethod = (callback: MyTypes.Function<number, string>) => { ... }