Currently, when using methods that accept NodePatternOptions such as Cypher.Pattern() and .to(), there is no enforcement of types in the key of properties.
By adding a type parameter on these methods and on NodePatternOptions, it is then possible to enforce type safety by using the keyof the type as the key of the Record
export type NodePatternOptions<T> = {
labels?: string | string[] | LabelExpr;
properties?: Record<keyof T, Expr>;
};
Example in TS Playground
Similarly, it would be nice to be able to specify a type on the .related() like:
export const VALID_RELATIONS = [
'HAS'
] as const
export type ValidRelations = (typeof VALID_RELATIONS)[number]
new Cypher.Pattern(...)
.related<ValidRelations>({ type: 'HAS'}) ✅
new Cypher.Pattern(...)
.related<ValidRelations>({ type: 'NO_LONGER_HAS'}) ❌
This ensures that when creating nodes, all properties are provided.