I'm trying to do a better typing with mongoose schemas, but it seems that the SchemaTypeOpts
interface has a [other: string]: any;
, which prevents the vcsode intellisense from helping me.
To solve that i tried the following in the hope that it would identify keys created by the dynamic propriety (since its name is other
):
const x: Pick<SchemaTypeOpts<any>, Exclude<keyof SchemaTypeOpts<any>, "other">> = {
bob: "", // expected an error here
type: String
}
but it seems Exclude
doesn't really do much when the interface has a dynamic property :/
ex: this works:
interface test2 {
x?: number,
y?: string,
z?: number,
}
const x: Pick<test2, Exclude<keyof test2, "z">> = {
y: "",
z: 5, // got error here because z is excluded
bob: "" //got error here because bob is not in the interface
}
this does nothing:
interface test2 {
x?: number,
y?: string,
z?: number,
[other: string]: any;
}
const x: Pick<test2, Exclude<keyof test2, "z">> = {
y: "",
z: 5,
bob: ""
}
How can i remove the [other: string]: any
from the interface without re-declaring the whole thing?