Skip to content

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

Open
@joshmossas

Description

@joshmossas

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions