Consider the below code example, I want to make it so that when we call the getResponse function with a function that contains an object that does not strictly match the type definition, it should cause a TS error. I do not want to use casting or strictly type the return. Essentially I want to enforce that whenever the getResponse function is called the return type is a strict mapping where it contains no extra properties (or has incorrect types for existing properties)
<code>type Response<T> = {
nested: {
status: 'degen' | 'based';
};
data: T;
};
type ResponseFn<T> = () => Response<T>;
function getResponse<T>(fn: ResponseFn<T>) {
return fn();
}
const response = getResponse<string>(() => ({
nested: {
status: 'degen',
invalidKey: 'invalidValue' // This should cause a TS error
},
data: 'no u'
}));
console.log(response);
</code>
<code>type Response<T> = {
nested: {
status: 'degen' | 'based';
};
data: T;
};
type ResponseFn<T> = () => Response<T>;
function getResponse<T>(fn: ResponseFn<T>) {
return fn();
}
const response = getResponse<string>(() => ({
nested: {
status: 'degen',
invalidKey: 'invalidValue' // This should cause a TS error
},
data: 'no u'
}));
console.log(response);
</code>
type Response<T> = {
nested: {
status: 'degen' | 'based';
};
data: T;
};
type ResponseFn<T> = () => Response<T>;
function getResponse<T>(fn: ResponseFn<T>) {
return fn();
}
const response = getResponse<string>(() => ({
nested: {
status: 'degen',
invalidKey: 'invalidValue' // This should cause a TS error
},
data: 'no u'
}));
console.log(response);