Effect CommunityEC
Effect Community6mo ago
1 reply
noah

Explicitly Passing `undefined` for Optional Fields in `makeRepository.insert`

Is it normal that I need to explicitly pass undefined to the makeRepository.insert function for fields that are optional for inserts to make sure I don't get a type error?
export class Session extends Model.Class<Session>('Session')({
  id: SessionId,
  userId: UserId,
  secretHash: Model.Sensitive(Schema.String),
  createdAt: Model.DateTimeInsert,
  lastVerifiedAt: Model.DateTimeUpdate
}) {}

const repo = yield* Model.makeRepository(Session, {
  tableName: 'session',
  idColumn: 'id',
  spanPrefix: 'SessionRepo',
})

yield* repo.insert({
  id: SessionId.make('1'),
  userId: UserId.make('1'),
  secretHash: 'test',
  // If I leave these fields out and don't explicitly pass undefined I get a type error
  createdAt: undefined,
  lastVerifiedAt: undefined,
})
Was this page helpful?