我试图继承const或将其扩展为另一个const
Parent.ts
export const Vehicle = {
'Name': 'Honda',
'NoOfWheels': '4'
}
Child.ts
import { Vehicle } from './Parent';
export const HondaVehicle = {
'VehicleName': 'Honda City',
'Color': 'Red',
'EngineCC': '2100cc',
}
所以我期望输出
{
'Name': 'Honda',
'NoOfWheels': '4',
'VehicleName': 'Honda City',
'Color': 'Red',
'EngineCC': '2100cc',
}
请帮助我。
答案 0 :(得分:2)
正如trichetriche所说,您可以使用spread syntax
import { Vehicle } from './Parent';
export const HondaVehicle = {
'VehicleName': 'Honda City',
'Color': 'Red',
'EngineCC': '2100cc',
...Vehicle
}
或者您可以使用Object.assign()
import { Vehicle } from './Parent';
export const HondaVehicle = Object.assign({
'VehicleName': 'Honda City',
'Color': 'Red',
'EngineCC': '2100cc',
}, Vehicle)
顺便说一下,这并不是Angular独有的,这是一个JavaScript东西。