-
Notifications
You must be signed in to change notification settings - Fork 6
Support for typing definition keys #529
Copy link
Copy link
Open
Description
Staying in line with using type safety, it would be great if typing support was built into the library by default for the type definition keys. Take a look at the following:
type DefinitionType<T> = {
[K in keyof T]: IField;
};
interface TypedIntermediateTypeOptions<T> extends IntermediateTypeOptions {
readonly definition: DefinitionType<T>;
}
class ExtendedInterfaceType<T> extends InterfaceType {
constructor(name: string, options: TypedIntermediateTypeOptions<T>) {
super(name, options);
}
}
export interface DataItem {
day: number;
month: number;
source: DataProvider;
timestamp: number;
year: number;
}
// will give an error since source is missing
export const DataItemType = new ExtendedInterfaceType<DataItem>("DataItem", {
definition: {
timestamp: GraphqlType.int(),
year: GraphqlType.int(),
month: GraphqlType.int(),
day: GraphqlType.int(),
},
});
// will not give an error since all properties are implemented
export const DataItemType = new ExtendedInterfaceType<DataItem>("DataItem", {
definition: {
timestamp: GraphqlType.int(),
year: GraphqlType.int(),
month: GraphqlType.int(),
day: GraphqlType.int(),
source: DataProviderEnumType.attribute(),
},
});We've made the choice to make the type required on the interface, ensuring consistent typing everywhere, but for this particular library it probably makes more sense to make it optional (will also ensure it isn't a breaking change).
I don't think the implementation would be a heavy lift, and am happy to submit a PR whenever I get a chance, but what do you all think about this functionality? Agree it makes sense to build it into the library?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels