I created a function with a parameter that is an Omit extension of another interface. I was hoping, that if I passed in an argument with the original (un-omitted) interface as its type, it would detect invalid properties on the argument. However, that doesn't appear to be the case. I'm curious about what I'm doing wrong here and if there is a way to successfully implement the example below.
interface Original {
a: string;
b: string;
c?: {
foo: string;
};
}
type OmittedExample = Omit<Original, "b" | "c">;
const data: Original = { a: "hello", b: "world", c: { foo: "bar" } };
const someFunction = (arg: OmittedExample) => {
console.log(arg);
/*
logs { a: "hello", b: "world", c: { foo: "bar" } }
*/
};
// TS doesn't detect that `data` is of type 'Original' and not 'OmittedExample'.
someFunction(data)
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment