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

Version 3 #231

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Version 3 #231

wants to merge 3 commits into from

Conversation

stephenwf
Copy link
Member

@stephenwf stephenwf commented Sep 24, 2024

Some improvements that I'd like to make:

  • Fix union types
  • Remove generic building of main types
  • Ensure supported services are valid
  • Add generic types to create Normalized variants programatically
  • Add more type tests
  • Add cast() function to package, 3 sigs:
    • cast({ type: 'Manifest' }) -> Manifest
    • cast<'Manifest'>({}) -> Manifest
    • cast({}, 'Manifest') -> Manifest

Cast function

At the moment this package isn't a fully-typescript only package - it does have an empty JS file. For non-typescript projects in an IDE like VSCode this can still be useful if the types are available. The cast function will be an essentially empty (a) => a function with types.

Casting fixed values.
Use case: test fixtures.

const manifest = {
  id: '...',
  type: 'Manifest',
  // ...
};

const typedManifest = cast(manifest); // Typed inferred from `manifest.type` value

Casting based on known type

const manifest = await fetchManifest(); // { id: ... }

const typedManifest = cast(manifest, 'Manifest'); // Type inferred from second argument

Casting with generic (TS ONLY)

const manifest = await fetchManifest();

const typedManifest = cast<'Manifest'>(manifest); // Type from generic argument and can be dynamic.

@IIIF-Commons IIIF-Commons deleted a comment from codesandbox bot Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant