jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.2k stars 505 forks source link

Knex namespace import type checking issue #1095

Open leshy opened 2 years ago

leshy commented 2 years ago

Current Behavior

Compilation throws an error.

Test repo is here, https://github.com/leshy/knextest

File in question https://github.com/leshy/knextest/blob/main/src/index.ts

(typescript) Error: /.../knextest/src/index.ts(3,15): semantic error TS2694: Namespace '"/.../knextest/node_modules/knex/types/index".Knex' has no exported member 'QueryBuilder'.
Error: /.../knextest/src/index.ts(3,15): semantic error TS2694: Namespace '"/.../knextest/node_modules/knex/types/index".Knex' has no exported member 'QueryBuilder'.
    at error (/.../knextest/node_modules/rollup/dist/shared/node-entry.js:5400:30)
    at throwPluginError (/.../knextest/node_modules/rollup/dist/shared/node-entry.js:11878:12)
    at Object.error (/.../knextest/node_modules/rollup/dist/shared/node-entry.js:12912:24)
    at Object.error (/.../knextest/node_modules/rollup/dist/shared/node-entry.js:12081:38)
    at RollupContext.error (/.../knextest/node_modules/tsdx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:17237:30)
    at /.../knextest/node_modules/tsdx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:25033:23
    at arrayEach (/.../knextest/node_modules/tsdx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:545:11)
    at Function.forEach (/.../knextest/node_modules/tsdx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:9397:14)
    at printDiagnostics (/.../knextest/node_modules/tsdx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:25006:12)
    at Object.transform (/.../knextest/node_modules/tsdx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:29277:17)

Expected behavior

Compiling this index.ts by hand with tsc throws no errors and my IDE LSP is also ok with this code.
So (maybe incorrectly?) I'm expecting tsdx compilation to now throw an error as well.

Suggested solution(s)

I suppose the issue is somewhere within a rollup plugin potentially? I'm a bit unfamiliar with this stack thanks to tsdx abstracting it away..

It seems to me that tsdx compilation process is confused with namespaces and interfaces under the same name that Knex project defines?

This is a type def file in question on knex side: https://github.com/knex/knex/blob/master/types/index.d.ts

Your environment

  System:                                                                                                                                                                                                                                      
    OS: Linux 5.13 Arch Linux                                                                                                                                                                                                                  
    CPU: (8) x64 Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz                                                                                                                                                                                      
    Memory: 1.60 GB / 15.29 GB                                                                                                                                                                                                                 
    Container: Yes                                                                                                                                                                                                                             
    Shell: 3.0.2 - /bin/fish                                                                                                                                                                                                                   
  Binaries:                                                                                                                                                                                                                                    
    Node: 16.9.1 - /usr/bin/node                                                                                                                                                                                                               
    Yarn: 1.22.11 - /usr/bin/yarn                                                                                                                                                                                                              
    npm: 7.24.0 - /usr/bin/npm            
  npmPackages:
    tsdx: ^0.14.1 => 0.14.1 
    typescript: ^4.4.4 => 4.4.4 
  npmGlobalPackages:
    tsdx: 0.14.1

Thanks!