outerbase / sdk

Typescript ORM and automated model generation direct from your database schema. Supports Outerbase features for saved queries & AI.
https://outerbase.com
MIT License
12 stars 5 forks source link

Typescript tsconfig should use strict #16

Closed caleb-mabry closed 5 months ago

caleb-mabry commented 5 months ago

Problem

When working on this project, strictNullChecks isn't added to our tsconfig.json. While developing, this causes issues. For example, looking at query here, you can see parameters has the potential to be undefined. Because strictNullChecks isn't set to true, the IDE doesn't realize that parameters.forEach could be incorrect because parameters may be undefined.

  async query(query: string, parameters: Record<string, any>[] | undefined) {
    if (!this.api_key) throw new Error("Outerbase API key is not set");
    if (!query) throw new Error("Query was not provided");

    let params = {};
    parameters.forEach((param) => {
      Object.keys(param).forEach((key) => {
        params[key] = param[key];
      });
    });

Solution

Add the strictNullChecks value

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs" /* Specify what module code is generated. */,
    "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
    "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
    "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
    "skipLibCheck": true /* Skip type checking all .d.ts files. */,
    "declaration": true,
    "declarationMap": true,
    "outDir": "./dist" /* Redirect output structure to the directory. */,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "strictNullChecks": true
  },
  "include": ["./src/**/*"],
  "exclude": ["node_modules"]
}

Additional context

image
Brayden commented 5 months ago

Status: Accepted

Discussion: Proposal accepted to make the tsconfig strict instead of strictNullChecks. Had unanimous decision to move forward with this approach in our weekly Discord community call. Converting the issue from proposal to enhancement.