mirror-cockpit-project-cockpit/tsconfig.json

41 lines
1 KiB
JSON
Raw Normal View History

/*
* Config for `tsc` and `tsserver`, currently only used for typechecking.
* Our main build is via `esbuild` which can handle `.ts`, but doesn't do any
* checking on its own. To typecheck, run `tsc`.
*
* Extended JSON — comments and trailing commas are good here.
*/
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
typescript: enable --exactOptionalPropertyTypes In Typescript when you say interface iface { prop?: string; } it means that the `iface` type can have an optional property `prop` present, and if it is present it must be a string *or* `undefined`. The reason for that is that given an instance `x` of type `iface`, if you say `x.prop` then the result of that will be `undefined` if the property is missing, so in some sense the ideas of "missing" and "`undefined`" are semi-fungible. This idea that a property can be present but defined to `undefined` is incompatible with our definition of JsonObject, which doesn't permit `undefined` to appear as a value in JSON documents, and has gotten us into a lot of trouble in the past, trying to create types to describe things that the bridge sends to us, in cases where a field may or may not be present. It seems like the Typescript people changed their mind about this. In 4.4 they introduced the "recommended" `--exactOptionalPropertyTypes` flag which doesn't implicitly add `undefined` as a permitted value as a side-effect of using `?`. https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-4.html#exact-optional-property-types---exactoptionalpropertytypes This hasn't been made part of `--strict` yet because of how disruptive it would be. Let's switch this option on for our code and fix a couple of places where it causes problems. One example is the `id` field of `HelperTextItem`: it's optional, but if present, it must be a string. Fix a bit of whitespace in tsconfig.json while we're at it.
2024-06-11 05:04:08 -08:00
"exactOptionalPropertyTypes": true,
2026-06-02 04:45:06 -08:00
"noUncheckedSideEffectImports": false,
"incremental": true,
"jsx": "react",
"lib": [
"dom",
"es2021"
],
2026-06-02 04:45:06 -08:00
"types": ["*"],
"paths": {
"*": ["./pkg/lib/*"]
},
"noEmit": true, // we only use `tsc` for type checking
typescript: enable --exactOptionalPropertyTypes In Typescript when you say interface iface { prop?: string; } it means that the `iface` type can have an optional property `prop` present, and if it is present it must be a string *or* `undefined`. The reason for that is that given an instance `x` of type `iface`, if you say `x.prop` then the result of that will be `undefined` if the property is missing, so in some sense the ideas of "missing" and "`undefined`" are semi-fungible. This idea that a property can be present but defined to `undefined` is incompatible with our definition of JsonObject, which doesn't permit `undefined` to appear as a value in JSON documents, and has gotten us into a lot of trouble in the past, trying to create types to describe things that the bridge sends to us, in cases where a field may or may not be present. It seems like the Typescript people changed their mind about this. In 4.4 they introduced the "recommended" `--exactOptionalPropertyTypes` flag which doesn't implicitly add `undefined` as a permitted value as a side-effect of using `?`. https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-4.html#exact-optional-property-types---exactoptionalpropertytypes This hasn't been made part of `--strict` yet because of how disruptive it would be. Let's switch this option on for our code and fix a couple of places where it causes problems. One example is the `id` field of `HelperTextItem`: it's optional, but if present, it must be a string. Fix a bit of whitespace in tsconfig.json while we're at it.
2024-06-11 05:04:08 -08:00
"strict": true,
"target": "es2021",
},
"include": [
"pkg/**/*"
],
"exclude": [
// these are part of the build system, not the app
"pkg/lib/esbuild-*.js",
"pkg/lib/cockpit-*-plugin.js",
"pkg/lib/*2po.js"
],
}