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

auto-generate type definitions from the json schema #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

k-yle
Copy link
Collaborator

@k-yle k-yle commented Dec 26, 2024

Besides from iD, there are several typescript projects which use this library. Currently, each project has to write their own type-definitions (see examples from overpass-turbo and osmapp). This is inconvenient and the definitions could easily become out-of-date.

This PR uses json-schema-to-typescript to generate TS definition files for the main JSON files in dist/*. This means that the next release of @openstreetmap/id-tagging-schema will include .d.json.ts files - example here

Examples:

import fields from "id-tagging-schema/dist/fields.json";
fields // type-definitions are available for fields

// and definitions can be imported by name, like `Field` or `Preset`
import type { /* ... */ } from "id-tagging-schema";

Copy link
Collaborator

@tordans tordans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I really like to see more TS in our projects. It will make working with them a lot easier.

import shell from 'shelljs';
import YAML from 'js-yaml';
import marky from 'marky';
import { createRequire } from 'module';
import { compileFromFile } from 'json-schema-to-typescript';
import { toSafeString } from 'json-schema-to-typescript/dist/src/utils.js';
Copy link
Collaborator

@tordans tordans Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe ask in the repo to make this a public API?

I could not find any issue on this, yet https://github.com/search?q=repo%3Abcherny%2Fjson-schema-to-typescript+toSafeString&type=issues

@@ -30,7 +30,6 @@ export default [
'indent': ['off', 4],
'keyword-spacing': 'error',
'linebreak-style': ['error', 'unix'],
'no-await-in-loop': 'error',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference https://eslint.org/docs/latest/rules/no-await-in-loop
Don't see a reason why we would want to prevent this.

@@ -16,6 +16,7 @@
"chalk": "^5.0.1",
"glob": "^10.1.0",
"js-yaml": "^4.0.0",
"json-schema-to-typescript": "^15.0.3",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter if this is in devDependencies or dependencies? It is only used during build so I kind of expected it to be a devDependencies?

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