Closed
Description
Bug Report
🔎 Search Terms
generic constraints, generic types, multiple generics, generic type variable, type parameters
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics.
⏯ Playground Link
Playground link with relevant code
💻 Code
type PropertiesType = {[key:string]: any};
type RequiredPropertiesType<Props extends PropertiesType> = (Exclude<keyof Props, symbol>)[];
interface JSONSchemaObjectType<
Props extends PropertiesType,
RequiredProps extends RequiredPropertiesType<Props>
> {
properties: Props;
required?: RequiredProps;
additionalProperties?: boolean;
}
const DefineObject = <
Props extends PropertiesType,
RequiredProps extends RequiredPropertiesType<Props>,
Def extends JSONSchemaObjectType<Props, RequiredProps>
>(definition: Def) => {
// noop
}
DefineObject({
properties: {
test: "hi"
},
required: ["test", "broken like me"] // <-- no static type error
})
🙁 Actual behavior
The required
array accepts values that are not keys used in it's sibling properties
🙂 Expected behavior
The required
array is constrained to the keys used in it's sibling properties