komodojp / tinyld

Simple and Performant Language detection library for NodeJS
https://komodojp.github.io/tinyld/
MIT License
415 stars 12 forks source link

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

Closed leonardlin closed 2 years ago

leonardlin commented 2 years ago

Using tinlyd: 1.2.2

Steps:

Expected

Actual

`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.
kefniark commented 2 years ago

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 🤔

kefniark commented 2 years ago

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/

kefniark commented 2 years ago

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

leonardlin commented 2 years ago

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.

leonardlin commented 2 years ago

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"
    ]
}
kefniark commented 2 years ago

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.

leonardlin commented 2 years ago

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