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

Export "Metadata" type so that consumers can extend it #49

Open
joshmossas opened this issue Sep 9, 2023 · 1 comment
Open

Export "Metadata" type so that consumers can extend it #49

joshmossas opened this issue Sep 9, 2023 · 1 comment

Comments

@joshmossas
Copy link

Right now there is no way for consumers of this library to extend the metadata property in SharedFormProperties because SharedFormProperties isn't exported from the library.

Current Type Definition

// ./src/scheam.ts line 112
interface SharedFormProperties {
  definitions?: { [definition: string]: Schema };
  metadata?: { [name: string]: unknown };
  nullable?: boolean;
}

Proposed Change

export interface SharedFormProperties {
  definitions?: { [definition: string]: Schema };
  metadata?: SchemaMetadata;
  nullable?: boolean;
}

export interface SchemaMetadata {
  [key: string]: unknown;
}

Reasoning

In doing this tools and apps that consume this library can define type hints for metadata that they use similar to how people extend the request object in Fastify or Express. (See an example here: fastify/help#122 (comment))

Here is an example of what this would allow. Writing a .d.ts file like the following.

// jtd.d.ts
import "jtd"
declare module "jtd" {
  export interface SchemaMetadata {
     id?: string;
     description?: string;
  }
}

Results in type hints like this:
image

@joshmossas
Copy link
Author

If the proposal looks good to you I'd be willing to make a PR to get this feature working.

I have a working fork here but it diverges in other places.

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

No branches or pull requests

1 participant