I have a generic function createModel that accepts an options object with literal types, but the return type loses the literal type information.
interface ModelOptions extends Readonly<Record<string, any>> {
resourceId: string;
_relations?: Readonly<Record<string, ModelOptions>>;
}
const createModel = <const TModelOptions extends ModelOptions>(
options: TModelOptions,
) => {
return {
resourceId: options.resourceId,
};
};
const bojan = createModel({
resourceId: 'bojan',
_relations: {
someKey: createModel({
resourceId: 'Woop',
}),
},
});
// Wanted output:
// (property) resourceId: "bojan"
// Output I get:
// (property) resourceId: string
bojan.resourceId;