Skip to content

Entypescripten the search API helpers

Erwan Rouchet requested to merge type-search into master

Closes #1135 (closed)

This defines a generic type called NullableProperties<T>, which might be moved to a typing helpers file later if it proves useful somewhere else. This type makes it so that any property of the object is either of its type, or null, and there cannot be a combination of both. With the search API, this means this:

// Allowed
{
  // ...other properties...
  'transcription_id': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
  'transcription_text': 'something',
  'transcription_confidence': 0.42,
  'transcription_worker': 'some worker name'
}

// Allowed, because the confidence is declared as `number | null`
{
  // ...other properties...
  'transcription_id': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
  'transcription_text': 'something',
  'transcription_confidence': null,
  'transcription_worker': 'some worker name'
}

// Allowed
{
  // ...other properties...
  'transcription_id': null,
  'transcription_text': null,
  'transcription_confidence': null,
  'transcription_worker': null
}

// Forbidden, because you can't have a transcription without a text
{
  // ...other properties...
  'transcription_id': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
  'transcription_text': null,
  'transcription_confidence': null,
  'transcription_worker': 'some worker name'
}

This makes the templates in the typed search components after #1157 (closed) much simpler, since if (thing.transcription_id) implies thing.transcription_text is never null.

Merge request reports

Loading