
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
tst-reflect
Advanced tools
This package is runtime part of tst-reflect-transformer, which is TypeScript transformer/plugin generating Type metadata objects that are working at runtime, providing
information about types such as list of properties and their types, list of constructors and their parameters and types and so on.
With working runtime generic types!
Visit Github repository for more information
import { getType } from "tst-reflect";
interface IFoo {}
class Foo implements IFoo {}
getType<IFoo>();
getType<Foo>();
getType(Foo);
const foo = new Foo();
getType<typeof foo>();
getType(foo);
import { getType, Type } from "tst-reflect";
function printClassInfo<TType>()
{
const type: Type = getType<TType>(); // <<== get type of generic TType
console.log(type.name); // > Animal
console.log(type.fullName); // > @@this/index.ts:Animal#21869
console.log(type.getProperties().map(p => `${p.name}: ${p.type.name}`).join("\n")); // > name: string
console.log(type.getMethods().map(m => `${m.name}(): ${m.returnType.name}`).join("\n")); // > makeSound(): string
return type.name;
}
abstract class Animal
{
private name: string;
abstract makeSound(): string;
}
printClassInfo<Animal>();
npm i tst-reflect && npm i tst-reflect-transformer -D
npm i ttypescript -D
tsconfig.json{
"compilerOptions": {
// your options...
// ADD THIS!
"plugins": [
{
"transform": "tst-reflect-transformer"
}
]
}
}
ttsc instead of tscnpx ttsc
Modify your webpack config. Use options.compiler of ts-loader to set ttypescript compiler.
({
test: /\.(ts|tsx)$/,
loader: require.resolve("ts-loader"),
options: {
compiler: "ttypescript"
}
})
Install Parcel plugin.
npm i parcel-plugin-ttypescript
Install Rollup plugin
npm i rollup-plugin-typescript2
and modify your rollup config.
import ttypescript from "ttypescript";
import tsPlugin from "rollup-plugin-typescript2";
export default {
// your options...
plugins: [
// ADD THIS!
tsPlugin({
typescript: ttypescript
})
]
}
Modify your tsconfig.json.
{
"compilerOptions": {
// your options...
"plugins": [
{
"transform": "tst-reflect-transformer"
}
]
},
// ADD THIS!
"ts-node": {
// This can be omitted when using ts-patch
"compiler": "ttypescript"
},
}
Runtime package (tst-reflect) contains two main exports, getType<T>() function and Type class. To get Type instance, you have to call getType<InterfaceOrClassOrSomeType>().
Transformer looks for all calls of getType<T>() and replace those calls by Type retrieving logic. It generates object literals describing referred types and instances of Type
are created from those objects.
Mentioned object literals describing types are called metadata. Default behavior collect metadata of all used types and generate file metadata.lib.js in project root (
location of tsconfig.json).
Metadata library file looks like this:
var {getType} = require("tst-reflect");
getType({
k: 5,
props: [{n: "foo", t: getType({n: "string", k: 2})}, {
n: "bar",
t: getType({k: 3, types: [getType({k: 6, v: "a"}), getType({k: 6, v: "b"})], union: true, inter: false})
}]
}, 22974);
getType({k: 5, props: [{n: "foo", t: getType({n: "string", k: 2})}, {n: "bar", t: getType({n: "string", k: 2})}]}, 22969);
getType({
n: "SomeType",
fn: "..\\logger.ts:SomeType",
props: [{n: "array", t: getType({k: 4, n: "Array", args: [getType(22969)]})}],
ctors: [{params: []}],
k: 1,
ctor: () => SomeType
}, 22965);
getType({
n: "Foo",
fn: "..\\logger.ts:Foo",
props: [{n: "prop", t: getType({n: "number", k: 2})}],
ctors: [{params: [{n: "prop", t: getType({n: "number", k: 2})}]}],
k: 1,
ctor: () => Foo
}, 22976);
More information in README in the root repository folder.
Or check examples or dev scripts we use to test things.
This project is licensed under the MIT license.
FAQs
Runtime of TypeScript Transformer for Runtime Types & Reflection
The npm package tst-reflect receives a total of 1,996 weekly downloads. As such, tst-reflect popularity was classified as popular.
We found that tst-reflect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.