In my code, I am dealing with a parent object of type 'any' that remains constant and cannot be changed. Within this context, I need to define a property for the parent object, but no matter what I try, it always ends up being loosely typed as 'any'. Even casting the property doesn't seem to have any effect until runtime. Is there a method to strongly type this property before runtime so that TypeScript can detect and throw an error when attempting to assign an incorrect property?
interface AType {
bar: number
bas: string
}
let something: any = {};
// Enforce 'AType' typing for this property.
something.anythingElse = <AType>{
bar: 1,
bas: 'one',
};
// Despite the issue, it should throw an Error
something.anythingElse.bogusAssignment = '1234';