I was trying to use conditional type but it does not work as expected. I was expecting type of abc would be number but it returns a string. Any help on the same would be appreciated.
class TableIdClass {
public tableId?: string;
constructor(props: TableIdClass) {
const { tableId } = props;
this.tableId = `${Math.random()}`;
}
}
export class TableBase extends TableIdClass {
public createDate?: Date;
constructor(props: TableBase) {
super(props)
const { createDate } = props;
this.createDate = (createDate) ? createDate : new Date();
}
}
export class EntityBase extends TableBase {
public entityId?: string;
public entityName?: string;
public isActive?: boolean;
constructor(props: EntityBase) {
super(props)
const { entityId, entityName, isActive } = props;
this.entityId = entityId;
this.entityName = (entityName) ? entityName : '';
this.isActive = (typeof isActive === 'undefined') ? true : isActive;
}
};
class SomeClass extends TableIdClass {
constructor(prop: SomeClass) {
super(prop)
}
}
type abc = SomeClass extends EntityBase ? string : number; // Returns string.