Skip to content

Narrow types for loaded normalized resourcesΒ #1

@stephenwf

Description

@stephenwf

Currently the types for ManifestNormalized and other resources do not match the IIIF specification, instead assume almost completely optional resource (for cases where a manifest, collection or annotation page has not been loaded yet). However there are times where you may know that a resource has been loaded.

Adding variations for these loaded resources: LoadedManifestNormalized with the specification constraints would allow for more accurate types. This could be a return value from vault.loadManifest() for example, and could also be used manually to narrow types.

function isLoaded(manifest: ManifestNormalized): manifest is LoadedManifestNormalized {
  return manifest.items.length > 0;
}

manifest = { ... }; // ManifestNormalized;

if (isLoaded(manifest)) {
  // manifest Narrowed to LoadedManifestNormalized.
  manifest.label; // no errors
  manifest.items[0].type; // no errors. 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions