Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrow types for loaded normalized resources #1

Open
stephenwf opened this issue Apr 27, 2022 · 0 comments
Open

Narrow types for loaded normalized resources #1

stephenwf opened this issue Apr 27, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@stephenwf
Copy link
Member

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. 
}
@stephenwf stephenwf added the enhancement New feature or request label Apr 27, 2022
@stephenwf stephenwf transferred this issue from IIIF-Commons/presentation-3-types Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant