Gathering detailed insights and metrics for ts-transformer-keys
Gathering detailed insights and metrics for ts-transformer-keys
Gathering detailed insights and metrics for ts-transformer-keys
Gathering detailed insights and metrics for ts-transformer-keys
@simplysm/ts-transformer-keys
심플리즘 패키지 - key 변환 (duo)
ts-interface-keys-transformer
`ts-interface-keys-transformer` is inspired by [ts-transformer-keys](https://github.com/kimamula/ts-transformer-keys). It uses custom transformer to parse the keys in 'interface' and 'type' in compile stage in TypeScript which support nested keys and opt
ts-keys-turn
A TypeScript custom transformer which enables to obtain keys of given type.
rbxts-transformer-keys
A TypeScript custom transformer which enables to obtain keys of given type.
A TypeScript custom transformer which enables to obtain keys of given type
npm install ts-transformer-keys
Typescript
Module System
Node Version
NPM Version
TypeScript (80.11%)
JavaScript (19.89%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
783 Stars
169 Commits
81 Forks
6 Watchers
4 Branches
5 Contributors
Updated on Jul 15, 2025
Latest Version
0.4.4
Package Id
ts-transformer-keys@0.4.4
Unpacked Size
13.07 kB
Size
4.35 kB
File Count
7
NPM Version
8.19.2
Node Version
16.18.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
4
A TypeScript custom transformer which enables to obtain keys of given type.
TypeScript >= 2.4.1
This package exports 2 functions.
One is keys
which is used in TypeScript codes to obtain keys of given type, while the other is a TypeScript custom transformer which is used to compile the keys
function correctly.
keys
1import { keys } from 'ts-transformer-keys'; 2 3interface Props { 4 id: string; 5 name: string; 6 age: number; 7} 8const keysOfProps = keys<Props>(); 9 10console.log(keysOfProps); // ['id', 'name', 'age']
Unfortunately, TypeScript itself does not currently provide any easy way to use custom transformers (See https://github.com/Microsoft/TypeScript/issues/14419). The followings are the example usage of the custom transformer.
See examples/webpack for detail.
1// webpack.config.js 2const keysTransformer = require('ts-transformer-keys/transformer').default; 3 4module.exports = { 5 // ... 6 module: { 7 rules: [ 8 { 9 test: /\.ts$/, 10 loader: 'ts-loader', // or 'awesome-typescript-loader' 11 options: { 12 // make sure not to set `transpileOnly: true` here, otherwise it will not work 13 getCustomTransformers: program => ({ 14 before: [ 15 keysTransformer(program) 16 ] 17 }) 18 } 19 } 20 ] 21 } 22}; 23
See examples/rollup for detail.
1// rollup.config.js 2import resolve from 'rollup-plugin-node-resolve'; 3import typescript from 'rollup-plugin-typescript2'; 4import keysTransformer from 'ts-transformer-keys/transformer'; 5 6export default { 7 // ... 8 plugins: [ 9 resolve(), 10 typescript({ transformers: [service => ({ 11 before: [ keysTransformer(service.getProgram()) ], 12 after: [] 13 })] }) 14 ] 15};
See examples/ttypescript for detail. See ttypescript's README for how to use this with module bundlers such as webpack or Rollup.
1// tsconfig.json 2{ 3 "compilerOptions": { 4 // ... 5 "plugins": [ 6 { "transform": "ts-transformer-keys/transformer" } 7 ] 8 }, 9 // ... 10}
See examples/ts-jest for details. In order to use this transformer with ts-jest, you need to add a wrapper around it like this:
1// ts-jest-keys-transformer.js 2const keysTransformer = require('ts-transformer-keys/transformer').default; 3const name = 'my-key-transformer'; 4const version = 1; 5const factory = (cs) => (ctx) => keysTransformer(cs.program)(ctx); 6// For ts-jest 26 use: 7// const factory = (cs) => (ctx) => keysTransformer(cs.tsCompiler.program)(ctx); 8 9module.exports = { name, version, factory };
And add it in jest.config.js
like this:
1 globals: { 2 'ts-jest': { 3 // relative path to the ts-jest-keys-transformer.js file 4 astTransformers: { before: ['src/react/ts-jest-keys-transformer.js'] }, 5 }, 6 },
Note: ts-jest 26.4.2 does not work with this transformer (fixed in ts-jest 26.4.3). Also, for versions smaller than 26.2, you need to provide the transformer in an array instead, like this: astTransformers: { before: ['src/react/ts-jest-keys-transformer.js'] }
See test for detail.
You can try it with $ npm test
.
1const ts = require('typescript'); 2const keysTransformer = require('ts-transformer-keys/transformer').default; 3 4const program = ts.createProgram([/* your files to compile */], { 5 strict: true, 6 noEmitOnError: true, 7 target: ts.ScriptTarget.ES5 8}); 9 10const transformers = { 11 before: [keysTransformer(program)], 12 after: [] 13}; 14const { emitSkipped, diagnostics } = program.emit(undefined, undefined, undefined, false, transformers); 15 16if (emitSkipped) { 17 throw new Error(diagnostics.map(diagnostic => diagnostic.messageText).join('\n')); 18}
As a result, the TypeScript code shown here is compiled into the following JavaScript.
1"use strict"; 2Object.defineProperty(exports, "__esModule", { value: true }); 3var ts_transformer_keys_1 = require("ts-transformer-keys"); 4var keysOfProps = ["id", "name", "age"]; 5console.log(keysOfProps); // ['id', 'name', 'age']
keys
function can only be used as a call expression. Writing something like keys.toString()
results in a runtime error.keys
does not work with a dynamic type parameter, i.e., keys<T>()
in the following code is converted to an empty array([]
).1class MyClass<T extends object> { 2 keys() { 3 return keys<T>(); 4 } 5}
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 1/3 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
20 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More