-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use with local ambient declarations #10
Comments
My thought process is that a consumer of this.tokenizers = Object.keys(paths).map(key => new Tokenizer(
key,
mapBaseUrl ? paths[key].map(mapBaseUrl) : paths[key]
))
} becomes: this.tokenizers = Object.keys(paths).filter(key => key !== '*').map(key => new Tokenizer(
key,
mapBaseUrl ? paths[key].map(mapBaseUrl) : paths[key]
))
} That would eliminate the transformation of any paths with a key that is only an asterisk. |
@shawnmcknight Probably fixed. Try version 1.6.6 of ts-transform-paths + ts-helpers |
Okay - I bumped my version of both and had some mixed results. When running through However, when running through "baseUrl": "./src",
"paths": {
"#mixins/*": [
"mixins/*"
],
"#shared/*": [
"shared/*"
],
"*": [
"types/*",
"../node_modules/*"
]
} Note: I removed the import { sign } from 'jsonwebtoken'; is being transformed when using const jsonwebtoken_1 = require("../../../../../../types/jsonwebtoken"); I reverted back to the 1.6.5 version of both modules and tested again. That behavior of the import from Based on that, I don't think the incorrect transformation is specific to relative paths. I believe the problem is really related to all non-aliased paths -- including imports from |
Right, only first entry in path array used,
Strange paths usage, do you really need it? Why not to create
Can you provide example? |
I think the idea here is that the global
I had hoped your suggestion was a solution I had missed, but it doesn't seem like typescript resolves folders named
The main difference between your project and mine is that my project has The path layout example I gave is that indicated here, in the TypeScript-Node-Starter repo from Microsoft's Github. I have not found any other way to ensure that ambient declarations local to the project get resolved, but I'm definitely open to suggestions there.
I'm not terribly concerned with that particular divergence because after removing the With that said, I'll work up a small example repo to illustrate my ongoing problem. |
I've created a repo with an example of the issue I'm having. On the The original source of import { Schema } from 'mongoose';
import beautifyUnique from 'mongoose-beautiful-unique-validation';
import { collation } from '#shared/configurations'; After building, you'll see that const mongoose_1 = require("../@types/mongoose");
const mongoose_beautiful_unique_validation_1 = __importDefault(require("../@types/mongoose-beautiful-unique-validation")); On the other hand, the require which was aliased through const configurations_1 = require("../shared/configurations"); If you switch to the
This is because without the |
Ok, got it. Adding "*" into tsconfig "paths" entry is a workaround, because typescript doesn't support per-module definitions outside DefinitelyTyped doesn't works locally. Typescript developers suggests above workarounds again and again: one, two, three I think about it in my plugin, but it's hard to resolve d.ts / module. |
Since |
Try 1.7.0, add exclude option to config: {
"compilerOptions": {
"plugins": [
{
"transform": "@zerollup/ts-transform-paths",
"exclude": ["*"]
}
]
}
} |
Looks like its doing the trick! Thank you! |
I'm having a problem using
ts-transform-paths
alongside localized ambient declarations that are accessible through thepaths
configuration.I'm utilizing an npm module that does not have its own
.d.ts
file and there is nothing in DefinitelyTyped@types
for it either. In this case, I've created my own ambient declaration.d.ts
file to substitute for it. In my project, I locate these declarations in./src/types
. Ordinarily typescript discovers these using apaths
andbaseUrl
configuration of:I'm now looking to add aliases and consume them through
ts-transform-paths
. I've adjusted mypaths
andbaseUrl
configuration to be:References to the aliases work perfectly after being processed by
ts-transform-paths
. However, non-aliased imports are being converted. For example, this import:has been transformed to:
If I eliminate the
*
property from thepaths
configuration, the transforming becomes correct:The only way I've found to continue to have my ambient declarations get resolved is to relocate them in a parent folder so that node's module resolution can find it rather than using typescript's paths, but I'd prefer to not have to locate these declarations directly in my
src
folder or in the project's root folder.Is there a manner in which I can configure my
tsconfig.json
to work for bothts-transform-paths
and for discovering the ambient declarations?Thanks!
The text was updated successfully, but these errors were encountered: