Skip to content

auto-generate type definitions from the json schema#177

Merged
tyrasd merged 1 commit intomainfrom
kh/types
Feb 25, 2026
Merged

auto-generate type definitions from the json schema#177
tyrasd merged 1 commit intomainfrom
kh/types

Conversation

@k-yle
Copy link
Copy Markdown
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
Copy Markdown
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.

@tyrasd tyrasd self-requested a review July 1, 2025 09:39
Copy link
Copy Markdown
Collaborator

@tyrasd tyrasd left a comment

Choose a reason for hiding this comment

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

It would be preferable if we could keep the no-await-in-loop linter rule. If the specific use here makes the file more easily readable, it's better to only disable the rule on that particular occurrence.

PS: for the types definitions to be imported as

import type { Field } from '@openstreetmap/id-tagging-schema';

we'd need to include "types": "./dist/index.d.ts" in package.json, right?

@k-yle
Copy link
Copy Markdown
Collaborator Author

k-yle commented Oct 24, 2025

done, also added ignoreMinAndMaxItems due to #242

@tyrasd
Copy link
Copy Markdown
Collaborator

tyrasd commented Feb 24, 2026

//ping @k-yle: IIRC when I tested this, the generated type definitions were only usable if I include "types": "./dist/index.d.ts" in package.json1, or is that not necessary?

Footnotes

  1. See https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package

@k-yle
Copy link
Copy Markdown
Collaborator Author

k-yle commented Feb 24, 2026

@tyrasd yes that's correct, that snippet will need to be added to id-tagging-schema's package.json, not the package.json in this repo

@tyrasd
Copy link
Copy Markdown
Collaborator

tyrasd commented Feb 25, 2026

Aaah, yes, that makes sense. Sorry, I was once again confused by there being two different repositories for the tagging schema 🙈

@tyrasd tyrasd merged commit 15c4e78 into main Feb 25, 2026
2 checks passed
@tyrasd tyrasd deleted the kh/types branch February 25, 2026 14:05
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.

3 participants