komodojp / tinyld

Simple and Performant Language detection library for NodeJS

Home Page:https://komodojp.github.io/tinyld/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compilation in typescript project with 'noImplicitAny: true' fails because of implict any in tinyld

leonardlin opened this issue · comments

Using tinlyd: 1.2.2

Steps:

  • include tinyld in a project that uses typescript setting noImplicitAny: true
  • run the typescript compiler (ie tcs )

Expected

  • It runs through

Actual

  • An error is thrown

node_modules/tinyld/src/core.ts:59:18 - error TS7018: Object literal's property 'only' implicitly has an 'any[]' type. 59 const data = { only: [], verbose: false } ~~~~~~~~

I will create a PR to address this.

that's an interesting one, I setup a more strict TS config

    "strict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "strictBindCallApply": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,

and yarn test:types which is running typescript compiler still doesn't complain about it when it complain in your project 🤔

I created a brand new project with noImplicitAny: true and I dont have any issue.
By any chance, can you provide me your tsconfig.json ?

It seems to be caused by the fact I directly point at typescript files and not use dedicated declaration files.
They are compile with the typescript config of the host project and not the one of the library, which can cause issues like this one.
I will check if I cannot remove the src/ and test/ folders from npm and only upload a types/

I just published a new version on npm tinyld@1.2.3

It should solve your problem and make the usage of the lib easier

thanks so much, I suspect it's related to the typescript version.
"implicitAny" checks got better and stricter with new versions.

I try the latest tinyld version and report back here.

The latest version works.
Thanks for fixing so quickly.

my tsconfig:

{
    "compilerOptions": {
        "module": "commonjs",
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "target": "es6",
        "declaration": true,
        "declarationMap": true,
        "lib": ["es6", "dom"],
        "noImplicitAny": true,
        "resolveJsonModule": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "outDir": "dist",
        "baseUrl": ".",
        "paths": {
            "*": [
                "node_modules/*",
                "src/types/*"
            ]
        }
    },
    "include": [
        "src/**/*",
    ],
    "exclude": [
        "src/**/*.spec.ts"
    ]
}

Thanks for your time and I'm really sorry for the different problems you run into 🤕

I will try to improve the flow and the documentation to make sure contributing to the project become a better process.

what are you talking about,
Thank you for this amazing lib!