Skip to content

AllowJS Not Working? #27398

@sdrioux

Description

@sdrioux

TypeScript Version: 3.1.1

Search Terms:
allowJS Implicitly has an 'any' type

TSConfig

{
    "compilerOptions": {
      "allowJs": true,
      "module": "commonjs",
      "noEmitOnError": true,
      "noFallthroughCasesInSwitch": true,
      "noImplicitReturns": true,
      "noUnusedLocals": true,
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "moduleResolution": "node",
      "resolveJsonModule": true,
      "strict": true,
      "target": "es2017",
      "lib": [
        "dom",
        "es2017",
        "es2018",
        "esnext"
      ],
  }

I am importing this JS file:

module.exports = {
  development: {
    username: "postgres",
    password: "",
    database: "development_database",
    host: "127.0.0.1",
    dialect: "postgres"
  },
  test: {
    username: "postgres",
    password: "",
    database: "test_database",
    host: "127.0.0.1",
    dialect: "postgres",
    logging: false
  }
}

like this:

import { Sequelize } from 'sequelize-typescript'
import * as sequelizeConfig from '../db/config'

const config = sequelizeConfig[process.env.NODE_ENV || 'development']
...
...

Expected behavior:
On 3.0.3 this compiles fine with no issues.

Actual behavior:
On 3.1.1 I get this error:

Element implicitly has an 'any' type because type '{ development: { username: string; password: string; database: string; host: string; dialect: string; }; test: { username: string; password: string; database: string; host: string; dialect: string; logging: boolean; }; }' has no index signature.

7 const config = sequelizeConfig[process.env.NODE_ENV || 'development']

I'm new to Typescript, but shouldn't allowJS: true prevent this scenario?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions