-
Notifications
You must be signed in to change notification settings - Fork 85
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
ts_transformer_keys_1.keys is not a function #4
Comments
I think I misunderstood something fundamental about how one is meant to use this! Will reopen if after more thorough testing I still can't get anywhere! |
@llanginger were you able to come up with a workaround. cause I too ran into the same issue trying to use this package. |
The error Could you show me how you are using the custom transformer to compile your TypeScript codes? |
Hi @kimamula I got around the issue.. was a problem with how i used the transformer. thanks for the library.. helps to solve a major issue i was facing with |
I get the same |
@martnst Sorry for the late response. |
@kimamula unfortunately, v0.3.1 does not work on Windows. |
FYI: I am on macOS |
@macbric @martnst I confirmed the following works both on macOS and Windows (with [email protected]).
import { keys } from 'ts-transformer-keys';
interface Props {
id: string;
name: string;
age: number;
}
const keysOfProps = keys<Props>();
console.log(keysOfProps);
const ts = require('typescript');
const keysTransformer = require('ts-transformer-keys/transformer').default;
const program = ts.createProgram(['index.ts'], {
strict: true,
noEmitOnError: true,
target: ts.ScriptTarget.ES5
});
const transformers = {
before: [keysTransformer(program)],
after: []
};
const { emitSkipped, diagnostics } = program.emit(undefined, undefined, undefined, false, transformers);
if (emitSkipped) {
throw new Error(diagnostics.map(diagnostic => diagnostic.messageText).join('\n'));
}
$ node compile # creates index.js
$ node index # outputs "[ 'id', 'name', 'age' ]" Could you provide your code so that I can investigate the problem? |
Hi, For me the code :
Gets compiled as :
And serves the error :
On windows, with typescript 2.9.2 and ts-transformer-keys 0.3.3. Best, Ludovic |
Hi, I have listed several ways of how to use custom transformers in README. |
I see you added support for your plugin to awesome-typescript-loader. But unfortunately I switched to ts-loader some time ago because of performance problems: s-panferov/awesome-typescript-loader#570 Any chance of added support in ts-loader? |
@tentreescantbeatme Sorry for the late reply. There is an issue on the ts-loader repository, so someone may working on it. |
@tentreescantbeatme this issue was fixed and |
Hello,
A simplified version of my code: my-inteface.ts
testTransformer.ts
I followed the webpack configuration as described here My configurations follow: angular.json
extra-webpack.config.js
!! Also i'm getting a worning Any ideas what is going wrong here? |
I am also using the same default webpack config as @Thanos-Pappas and am running into:
is there something missing from the webpack demo code? I am also running TS 3.2.2. |
I have same problem with EDIT: Instead of |
@Thanos-Pappas I tested I found several issues (such as this and this) suggesting that you have to use
This even happens when I use module.exports = {
module: {
rules: [
{
test: /\.ts$/,
loader: 'awesome-typescript-loader' // or 'ts-loader'
}
]
}
}; It is likely that
Note that webpack loaders are applied from the bottom to the top. As of now, I cannot think of any good solution for this issue. @gabbifish I haven't encountered |
I had the same problem i had to follow it using ttypescript.
I stopped getting the error after that 😅 |
For me the issue was that I used the fork-ts-checker-webpack-plugin and therefore set transpileOnly: true. If transpileOnly is true, this plugin does not work. Makes kinda sense, took me still quite a while to figure it out ;). TLDR: ensure transpileOnly is not set to true! Regards |
Hi @kimamula , Have you found the way to make this work with Angular or @ngtools/webpack? The best I was able to do is to patch @ngtools/webpack so it uses ttypescript, but not sure that is sustainable model. |
I did exactly the same thing here and it still does not work. |
I'm in the exact same scenario above. |
There is no such function as keys in the index.js file, kindly check that |
I have the same error TypeError: ts_transformer_keys_1.keys is not a function I do not have webpack I have only tsconfig.json and package.json How can I fix this error? |
How are you transforming |
I'm using TypeScript with React-Native, and error
and
How can i fix it? |
In case this helps anybody else: I was planning to use |
Can you show your |
I was able to get this working with Create React App by using https://github.com/timarney/react-app-rewired, https://www.npmjs.com/package/ttypescript, and https://www.npmjs.com/package/awesome-typescript-loader config-overrides.js
tsconfig.json
|
@dungnguyen10989 If you are using Babel, it is not possible to get the transformer work. See #32. |
I have this issue as well with pnpm when while using It can be fixed by changing ts-transformer-keys/transformer.ts Line 61 in 8a92a56
to import * as fs from 'fs';
...
&& (fs.realpathSync(path.join(declaration.getSourceFile().fileName)) === indexTs) Not sure if this is the right way to fix it. But it works. |
@vmirage Thanks for reporting! I will look for if there is a better way to resolve this problem. |
@vmirage I found that using |
@kimamula yup that works |
@kimamula I arrived late, but unfortunately in the same bug. Using version 0.4.2 TypeError: ts_transformer_keys_1.keys is not a function |
@luisdemarchi please provide a reproduction. Thanks! |
After testing this all day I think neither ts-transformer-keys or ts-interface-keys-transformer work with Webpack ts-loader when This kind of makes sense, and I've disabled the following seem related: TypeStrong/ts-loader#1002, https://stackoverflow.com/a/52034546/3754229 |
@benjamingwynn The doc of ts-loader says:
And I confirmed that adding |
@kimamula thank you for getting back to me! this is correct and solved the issue at hand ( I am using node_modules with uncompiled Typescript modules as part of my development environment. If it helps anyone else, ts-loader with Edit: cleared up solution |
I'm on a mac. it seems like it is working for me with ttypecript (vsc hinting shows me that I have an array of union of valid properties), but in ts-jest I am getting this error. I believe my setup is equivalent to what is provided in the readme.. I have the same custom file and this in package.json (instead of jest.config): "jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"roots": [
"<rootDir>/src"
],
"moduleDirectories": [
"node_modules",
"src"
],
"moduleNameMapper": {
"@lib/(.*)": "<rootDir>/src/lib/$1"
},
"globals": {
"ts-jest": {
"astTransformers": { "before": ["./ts-jest-keys-transformer.js"] }
}
}
nvm, I realized that I just forgot to run const factory = (cs) => (ctx) => {
console.log(keysTransformer)
return keysTransformer(cs.tsCompiler.program)(ctx)
}; |
Got the same problem when running it in vscode with jest-runner, |
I had to update the factory function to make it work using // notice cs.program instead of cs.tsCompiler.program
const factory = cs => ctx => keysTransformer(cs.program)(ctx); // 👈 no `tsCompiler` |
Using nodejs with ts-node as code
|
Was this fixed? |
Still ON |
For anyone still struggling with this, another fun wrinkle I ran into was that the uses of |
We had been using this succesfully, but were having a similar problem when attempting to update our libraries (especially node). I'd updated my devDependencies to use "typescript": "^4.2.3". The server would build, but when trying to use the keys function we'd get an error saying "ts_transformer_keys_1 is not defined". A coworker noticed that the devDependency on this package was ^3.9.5, so I did the same locally and it works again. |
It's work for me! |
nest.js + basic Jest testing jest.json
and added ts-jest-keys-transformer.js in same folder issue is that it warns |
Hi there!
This package sounds like the ideal solution to a problem I have but I am struggling to get past the following error: "TypeError: ts_transformer_keys_1.keys is not a function" and I am not sure how to tell if this is an error on my part or if there is something out of my control that is not working.
I have tried compiling the following file with typescript 2.4.0 and running in the browser with no other packages:
I have also tried using ts-node and executing the same file from the command line, though here in particular I am unsure to what extend ts-node is a bottleneck.
I hope I'm missing something super simple!
Thanks in advance for any thoughts in any direction!
The text was updated successfully, but these errors were encountered: