Commit Graph

3 Commits

Author SHA1 Message Date
Alois Klink 7c3a73d4a8 build(types): add script to generate Config types
Add script `packages/mermaid/scripts/create-types-from-json-schema.mts`
to automatically generate the TypeScript definition for `MermaidConfig`
from the `MermaidConfig` JSON Schema at
`packages/mermaid/src/schemas/config.schema.yaml`.

To do this, we are using this library
[`json-schema-to-typescript`][1], which is also used by Webpack to
generate their types from their JSON Schema.

In order to make sure that this isn't a breaking change, the script
makes all fields **optional**, as that is what the original typescript
file has.

Additionally, I've put in some custom logic into the script, so that
the exact same order is used for the TypeScript file, to make the
`git diff` easier to review. In the future, we can remove this custom
logic, once we no longer need to worry about `git merge` conflicts.

[1]: https://github.com/bcherny/json-schema-to-typescript
2023-07-06 03:53:40 +01:00
Alois Klink 79688a1dc1 build: forbid using TypeScript enums using eslint
[TypeScript enums][1] are an unusual TypeScript feature, because it's
one of the only features that is "not a type-level extension of
JavaScript".

This means TypeScript generates custom code for enums, which can cause a
bunch of issues, especially as this custom code can be built differently
depending on which bundler you use, and because of this, many people
discourage the use of enums:

- [The Dangers of TypeScript Enums][2]
- [Tidy TypeScript: Prefer union types over enums][3]
- [TypeScript: Handbook - Enums # Objects vs Enums][4]

I've added an ESLint rule that forbids TypeScript enums, as in most
cases, it's better to use string literals instead, e.g. like
`type a = "a" | "b" | "c";`.

[1]: https://www.typescriptlang.org/docs/handbook/enums.html#string-enums
[2]: https://dev.to/azure/the-dangers-of-typescript-enums-55pd
[3]: https://fettblog.eu/tidy-typescript-avoid-enums/
[4]: https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums
2023-07-03 00:04:16 +01:00
Sidharth Vinod afe3f593e1
fix(#4003): Remove unhandled promises
Add eslint rules to check for unhandled promises
Fix all existing unhandled promise issues
2023-01-18 00:47:49 +05:30