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

better exporting of types #43

Merged
merged 5 commits into from
Apr 13, 2023
Merged

better exporting of types #43

merged 5 commits into from
Apr 13, 2023

Conversation

tomasciccola
Copy link
Contributor

This PR addresses #39 and #38

@tomasciccola
Copy link
Contributor Author

I basically now generate a types/index.d.ts with the following contents:

export { ProtobufSchema } from './proto'
export { JSONSchema } from './schema'

both refer to a mixed type that can the be imported like:

/**
* @property {import('./types').JSONSchema} obj
*/

However one cannot access individual schemas from there like so:

/**
THIS WON'T WORK
* @property {import('./types').JSONSchema.Observation} observation
*/

Since i.e Observation is not actually a field inside JSONSchema.
To import individual types one would do smth like

/**
THIS WILL WORK
* @property {import('./types/schema').Observation} observation
*/

this works since each index.d.ts corresponding to JSONSchemas and Protobufs also export individual types referring every version of a schema or protobuf, where the identifier without a specific version corresponds to the last version (so Observation actually refers to Observation_5).

@tomasciccola
Copy link
Contributor Author

An alternative to referring to individual types would be exporting every JSONSchema and Proto types from types/index.d.ts, where we append an identifier like so

export { Observation_5 as ObservationProto } from './proto/observation/v5'
export { Observation_4 as ObservationProto_4 } from './proto/observation/v4'

this, I think, would allow to do smth like

/**
* @param {import ('./types').ObservationProto} observation
*/

instead of

/**
* @param {import ('./types/proto').Observation} observation
*/

I don't have any preferences, so open to suggestions...

@sethvincent
Copy link
Contributor

/**
THIS WILL WORK
* @property {import('./types/schema').Observation} observation
*/

this works since each index.d.ts corresponding to JSONSchemas and Protobufs also export individual types referring every version of a schema or protobuf, where the identifier without a specific version corresponds to the last version (so Observation actually refers to Observation_5).

Cool, that works for me. I'll do some quick experiments using/integrating this.

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.

2 participants