Skip to content

Typescript optional values should also be "key optional" #4516

@sean256

Description

@sean256

As of now the type definitions require this

await conn.reducers.updateCategory({
  id: BigInt(1),
  name: 'updated category name',
  buttonText: undefined,
  headerText: undefined,
  deleted: undefined,
});

However, the following works just fine, except for type errors

await conn.reducers.updateCategory({
  id: BigInt(1),
  name: 'updated category name',
});
Argument of type '{ id: bigint; name: string; }' is not assignable to parameter of type 'InferTypeOfRow<CoerceRow<{ id: U64Builder; name: OptionBuilder<StringBuilder>; buttonText: OptionBuilder<StringBuilder>; headerText: OptionBuilder<...>; deleted: OptionBuilder<...>; }>>'.
  Type '{ id: bigint; name: string; }' is missing the following properties from type 'InferTypeOfRow<CoerceRow<{ id: U64Builder; name: OptionBuilder<StringBuilder>; buttonText: OptionBuilder<StringBuilder>; headerText: OptionBuilder<...>; deleted: OptionBuilder<...>; }>>': buttonText, headerText, deleted

The reducer in question

const updateSchema = {
	id: t.u64(),
	name: t.string().optional(),
	buttonText: t.string().optional(),
	headerText: t.string().optional(),
	deleted: t.bool().optional(),
};

export const updateCategory = db.reducer(updateSchema, (ctx, input) => {
	/**update code here**/
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions