I have defination of object like:
let translateObj: ITranslate;
I tried to initializae this like corresponding interface:
let obj = new translateObj = {
keyTranslate: 'subjectId',
outName: 'name'
}
It does not work...Can I use this suffix?
I tried this:
export class MapperServiceArray<T> implements IMapperServiceArray<T> {
public constructor(public key: string | number, public translate?: ITranslate) {
}
I create instance like this:
let mapperArray = new MapperServiceArray<ISubjectBase>('subjectId', {
keyTranslate: 'subjectId',
outName: 'name'
});
Why you use new translateObj
?
If you declare an interface and want your object to be of type of that interface, you need just set the type to it and initialize an object without new
.
let obj: ITranslate = {
keyTranslate: 'subjectId',
outName: 'name'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With