I am inexperienced with TypeScript and am looking to set up types for my object keys. I have explored a few methods to accomplish this, but I am encountering an issue where an error is not triggered when assigning a value of a different type. For example:
interface sectionProp {
_type1: String,
_columnStrechAllowed: Boolean,
_columnOccupancy: Number,
is_mandatory: Boolean
}
export class sectionProperties {
folioSectionContentProp = <sectionProp> {}
constructor(type?) {
this.folioSectionContentProp._type1 = type;
this.folioSectionContentProp._columnStrechAllowed = false;
this.folioSectionContentProp._columnOccupancy = 6;
this.folioSectionContentProp.is_mandatory = false;
}
}
export class createNewSection extends sectionProperties {
constructor() {
super("Test") // here I will assign value
// super(12) //@ this does not generate any error as well
// I might assign value by some other way (from object creation)
// but I want to know the reason if type is defined then it should
// not accept any value other than type
}
}
var z = new createNewSection();
console.log(z)
In conclusion, I am striving to ensure that my object keys are explicitly typed.
Many thanks