I wrote a piece of code to customize the default configuration for a Class, but I encountered an unusual error message:
Type 'IConfig' is not assignable to type 'import("/Volumes/D/www/js/tsc_1/test").IConfig'.ts(2322)
It seems that I cannot simply assign the same variable type to another. Please refer to the attached screenshots for details.
export default interface IPlugin {
setConfig<T>(config: T): T
}
export interface IConfig {
port: number
}
const _config: IConfig = {
port: 7001
}
class Server implements IPlugin {
public config : IConfig
constructor() {
this.config = _config
}
setConfig<IConfig>(configNew: IConfig) {
this.config = configNew
// ERROR - Type 'IConfig' is not assignable to type 'import("/Volumes/D/www/js/tsc_1/test").IConfig'.ts(2322)
return configNew
}
}
https://i.sstatic.net/rMJaZ.png https://i.sstatic.net/9jUVR.png