Closed billderose-zz closed 7 years ago
There should be no need for a declare module "tslib"
, as tslib.d.ts is the module and exports at the top level. Also package.json
declares tslib.d.ts
as the typings for the package. What issue are you seeing?
@rbuckton thanks for the response. I think the issue stems from the fact that I'm consuming tslib
via bower (https://github.com/Draccoz/tslib). Running bower install tslib --save
installs into my vendor
directory but at compile time, I get:
error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
My tsconfig.json
looks like:
{
"compilerOptions": {
"experimentalDecorators": true,
"importHelpers": true,
"jsx": "react",
"module": "amd",
"noEmitHelpers": true,
"target": "es5",
"typeRoots": [
"./typings/**/*.d.ts",
"../vendor/tslib/tslib.d.ts"
]
}
}
If I copy/paste the declare module 'tslib' {...}
from my initial comment, into the typings directory then the build goes through with no complaints. I'm guessing this is a non-standard way of consuming the package?
I think part of the issue is that your "typeRoots"
definition is incorrect. The "typeRoots"
field should point to folders only, and does not support globs. Please refer to www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types for more information.
Interesting, and good to know. When I change my tsconfig.json
to
{
...
"typeRoots": [ "./typings", "../vendor/tslib"]
}
I get more compiler errors about not being able to find all the modules whose typings are declared in ./typings
, e.g. error TS2688: Cannot find type definition file for 'node'.
. I also still get the error about not being able to find the tslib
module: error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
I'm now wondering if this is due to a mismatch in the module resolution required for the respective modules??
You should be able to accomplish this via path mapping:
tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": { "tslib": ["../vendor/tslib/tslib.d.ts"] }
}
}
Also updated in the readme: https://github.com/Microsoft/tslib/blob/master/README.md#for-bower-users
Right now,
tslib.d.ts
does not contain a module declaration for'tslib
' and instead declares the functions in the global namespace. As of TS 2.1.4, when I enable the--noEmitHelpers
and--importHelpers
compiler flags, my build fails because it cannot find the required'tslib'
module.I'm opening an issue because there's probably a reason this hasn't been done already, but wouldn't it be possible to do something like:
@billti @rbuckton @sandersn for visibility