Let's say I have the object:
const styles = { product: { color: 'blue' } };
and with that the object type is inferred and I can access foo.bar.baz without a problem.
However, if I wanted type checking, I would need something like:
import type CSS from 'csstype';
type StyleSheet = Record<string,CSS.Properties>;
const styles:StyleSheet = {
product: { color: 'blue' }
};
And the above would be valid, however, when accessing styles I would get styles.whatever.color or styles.product.margin as defined, which is undesired.
With that in mind, is there any way in Typescript to infer the original type of the object after it has been typed, so I can access its real properties, like so:
const styles:StyleSheet = { product: { color: 'blue' } }; // typed as 'StyleSheet' so I get type-checking
styles.whatever.margin // TS thinks this is valid because of the index signature;
const original = styles as OriginalObject; // infer original type so only real properties are accessible
original.whatever // invalid (expected)
original.product.color // valid
export default original;
Update
replying @jcalx's: