请教一个有关typescript的申明合并问题
用到一个模块eureka-js-client
,在@types
里的申明如下:
// Type definitions for eureka-js-client 4.3
// Project: https://github.com/jquatier/eureka-js-client
// Definitions by: Ilko Hoffmann <https://github.com/Schnillz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export class Eureka {
constructor(config: EurekaClient.EurekaConfig)
start(): void;
stop(): void;
getInstancesByAppId(appId: string): string[];
getInstancesByVipAddress(vidAddress: string): string [];
}
export namespace EurekaClient {
type InstanceStatus = 'UP' | 'DOWN' | 'STARTING' | 'OUT_OF_SERVICE' | 'UNKNOWN';
type ActionType = 'ADDED' | 'MODIFIED' | 'DELETED';
type DataCenterName = 'Netflix' | 'Amazon' | 'MyOwn';
interface EurekaConfig {
instance: EurekaInstanceConfig;
eureka: EurekaClientConfig;
}
interface EurekaInstanceConfig {
app: string;
hostName: string;
ipAddr: string;
vipAddress: string;
dataCenterInfo: DataCenterInfo;
port?: number;
instanceId?: string;
appGroupName?: string;
sid?: string;
securePort?: PortWrapper;
homePageUrl?: string;
statusPageUrl?: string;
healthCheckUrl?: string;
secureHealthCheckUrl?: string;
secureVipAddress?: string;
countryId?: number;
status?: InstanceStatus;
overriddenstatus?: InstanceStatus;
leaseInfo?: LeaseInfo;
isCoordinatingDiscoveryServer?: boolean;
}
interface EurekaClientConfig {
host: string;
port: number;
heartbeatInterval?: number;
registryFetchInterval?: number;
maxRetries?: number;
requestRetryDelay?: number;
fetchRegistry?: boolean;
filterUpInstances?: boolean;
servicePath?: string;
ssl?: boolean;
useDns?: boolean;
preferSameZone?: boolean;
clusterRefreshInterval?: boolean;
fetchMetadata?: boolean;
registerWithEureka?: boolean;
useLocalMetadata?: boolean;
preferIpAddress?: boolean;
}
interface PortWrapper {
enabled: boolean;
port: number;
}
interface LeaseInfo {
renewalIntervalInSecs: number;
durationInSecs: number;
}
interface DataCenterInfo {
name: DataCenterName;
}
}
但是这个定义有点儿过时了,DataCenterInfo
接口里新增了一个@class
字段,现在我试了各种方法都无法合并新的字段进去,这是我现在在项目的某个d.ts
文件里写得:
declare namespace EurekaClient {
interface DataCenterInfo {
'@class': string
}
}
报错如下: 以上只是我申明的一种方法,已经试了不少写法了,实在懵逼了,难道要重写整个声明才行么,请教各位大神了。