it-gorillaz / configify

NestJS Config on Steroids
MIT License
61 stars 4 forks source link

Cannot use the package with strict typescript config #46

Open mrsafalpiya opened 1 month ago

mrsafalpiya commented 1 month ago

Short description

Currently this package cannot be used when we use strict typescript configuration.

Steps to reproduce

  1. nest new foo --strict (Note the --strict argument)
  2. npm install --save @itgorillaz/configify
  3. Add ConfigifyModule in the imports array in app.module.ts:
@Module({
  imports: [ConfigifyModule.forRootAsync()],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
  1. npm run start:dev

We get the following error:

node_modules/@itgorillaz/configify/src/configify.module.ts:235:15 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
    Argument of type 'string | string[] | undefined' is not assignable to parameter of type 'ConcatArray<never>'.
      Type 'undefined' is not assignable to type 'ConcatArray<never>'.
  Overload 2 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
    Argument of type 'string | string[] | undefined' is not assignable to parameter of type 'ConcatArray<never>'.
      Type 'undefined' is not assignable to type 'ConcatArray<never>'.

235       .concat(path, this.DEFAULT_CONFIG_FILES)
                  ~~~~

node_modules/@itgorillaz/configify/src/configuration/configuration.registry.ts:22:24 - error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

22     this.registry.push(type);
                          ~~~~

node_modules/@itgorillaz/configify/src/configuration/parsers/configuration-parser.factory.ts:30:12 - error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ env: DotEnvConfigurationParser; yml: YamlConfigurationParser; yaml: YamlConfigurationParser; json: JsonConfigurationParser; }'.
  No index signature with a parameter of type 'string' was found on type '{ env: DotEnvConfigurationParser; yml: YamlConfigurationParser; yaml: YamlConfigurationParser; json: JsonConfigurationParser; }'.

30     return this.parsers[ext];
              ~~~~~~~~~~~~~~~~~

node_modules/@itgorillaz/configify/src/configuration/parsers/configuration-parser.factory.ts:51:5 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

51     return file.split('.').pop();
       ~~~~~~

node_modules/@itgorillaz/configify/src/configuration/parsers/yaml-configuration.parser.ts:2:23 - error TS7016: Could not find a declaration file for module 'js-yaml'. '/home/safal/work/templates/nestjs/template/node_modules/js-yaml/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/js-yaml` if it exists or add a new declaration (.d.ts) file containing `declare module 'js-yaml';`

2 import * as yaml from 'js-yaml';
                        ~~~~~~~~~

node_modules/@itgorillaz/configify/src/configuration/resolvers/aws/parameter-store-configuration.resolver.ts:39:46 - error TS18048: 'e.error' is possibly 'undefined'.

39           .map((e) => `${e.key}: ${e.id} - ${e.error.message}`)
                                                ~~~~~~~

node_modules/@itgorillaz/configify/src/configuration/resolvers/aws/secrets-manager-configuration.resolver.ts:42:46 - error TS18048: 'e.error' is possibly 'undefined'.

42           .map((e) => `${e.key}: ${e.id} - ${e.error.message}`)
                                                ~~~~~~~

node_modules/@itgorillaz/configify/src/interpolation/variables.ts:44:7 - error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'.

44       expanded[key] =
         ~~~~~~~~~~~~~

System information

package.json contents:

{
  "name": "foo",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@itgorillaz/configify": "^1.2.3",
    "@nestjs/common": "^10.0.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/platform-express": "^10.0.0",
    "reflect-metadata": "^0.2.0",
    "rxjs": "^7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.0.0",
    "@nestjs/schematics": "^10.0.0",
    "@nestjs/testing": "^10.0.0",
    "@types/express": "^4.17.17",
    "@types/jest": "^29.5.2",
    "@types/node": "^20.3.1",
    "@types/supertest": "^6.0.0",
    "@typescript-eslint/eslint-plugin": "^8.0.0",
    "@typescript-eslint/parser": "^8.0.0",
    "eslint": "^8.42.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.0",
    "jest": "^29.5.0",
    "prettier": "^3.0.0",
    "source-map-support": "^0.5.21",
    "supertest": "^7.0.0",
    "ts-jest": "^29.1.0",
    "ts-loader": "^9.4.3",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.1.3"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}
tommelo commented 1 month ago

@mrsafalpiya thanks for reporting it! I'll add this to the backlog and work on supporting the strict config.

It's mostly strictNullChecks and noImplicitAny that needs to be addressed in the implementation.

mrsafalpiya commented 1 month ago

Hello @tommelo I have created a PR to resolve this issue. Please take a look at it.

tommelo commented 1 month ago

@mrsafalpiya thanks for submitting the PR! I'll have a look as soon as I have some free time.