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

json-schema-to-typescript doesn't work #7

Closed
yorinasub17 opened this issue Nov 18, 2023 · 4 comments
Closed

json-schema-to-typescript doesn't work #7

yorinasub17 opened this issue Nov 18, 2023 · 4 comments

Comments

@yorinasub17
Copy link
Member

json-schema-to-typescript doesn't work because it emits types using index signatures for complex schemas using patternProperties and additionalProperties, which can be incompatible when mixed.

See bcherny/json-schema-to-typescript#356

Here are the current error messages

node_modules/.pnpm/@[email protected]/node_modules/@fensak-io/senc-jsonschema-githubactions/index.d.ts:376:3 - error TS2411: Property 'types' of type 'Types14 | undefined' is not assignable to 'string' index type 'unknown[]'.

376   types?: Types14;
      ~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@fensak-io/senc-jsonschema-githubactions/index.d.ts:541:3 - error TS2411: Property 'branches' of type 'Branch | undefined' is not assignable to 'string' index type 'string[]'.

541   branches?: Branch;
      ~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@fensak-io/senc-jsonschema-githubactions/index.d.ts:542:3 - error TS2411: Property '"branches-ignore"' of type 'Branch | undefined' is not assignable to 'string' index type 'string[]'.

542   "branches-ignore"?: Branch;
      ~~~~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@fensak-io/senc-jsonschema-githubactions/index.d.ts:543:3 - error TS2411: Property 'tags' of type 'Branch | undefined' is not assignable to 'string' index type 'string[]'.

543   tags?: Branch;
      ~~~~

node_modules/.pnpm/@[email protected]/node_modules/@fensak-io/senc-jsonschema-githubactions/index.d.ts:544:3 - error TS2411: Property '"tags-ignore"' of type 'Branch | undefined' is not assignable to 'string' index type 'string[]'.

544   "tags-ignore"?: Branch;
@yorinasub17
Copy link
Member Author

NOTE: you can work around this by disabling strict null check. It's not great, but at least it's better than status quo.

@yorinasub17
Copy link
Member Author

yorinasub17 commented Nov 18, 2023

This mostly gets fixed with the strictIndexSignatures setting in json-schema-to-typescript. However, it fails to append the | undefined type modifier for nested patternProperties.

For now, we manually edit the generated file to fix these errors (look for comment, // MANUALLY UPDATED).

@yorinasub17
Copy link
Member Author

Opened PR with fix bcherny/json-schema-to-typescript#560

@yorinasub17
Copy link
Member Author

Worked around for now with a pnpm patch.

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