
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
A enhanced (unofficial) version of the TypeScript compiler that provides Reflection capabilities.
Releases follow the official ones, so I try to keep the same scheme. For the latest stable version:
npm install -g reflec-ts
For the latest available version:
npm install -g reflec-ts@next
I try to keep reflec-ts master aligned with the official one, at least weekly.
You can find some examples here.
Every language that offers real reflection capabilities has to provide two things, both at coding time and runtime:
Actually, if picked individually, these two features are not enough to achieve reflection, but they should be linked in some way. For example, we generally expect to retrieve class metadata from its identifier (for example String.class in Java), or we want to instantiate a new object from class metadata (Class.newInstance() in Java).
Here, this aspect has been the hardest one to implement, since the mere type serialization was already achieved some time ago by many people (LanguageService API is enough).
In order to link metadata with classes (constructors in JavaScript) reflec-ts injects some synthetic instructions in the AST, just after the parsing phase. These instructions do not contain all type information, but just link the metadata object with constructors. In a second phase, just before the usual JS code emitting, reflec-ts builds a special JS file (Reflection.js) that contains metadata for all types.
Since we modify the AST, types metadata are immediately visible from the IDE (LanguageService uses the same parser), so we can achieve something like the following:

As you can see, the compiler added some features, like getClass() method on the class and MyInterface literal, that contains all interface details.
It works exactly like the official TypeScript compiler. You can use reflec-tsc:
reflec-tsc -p /path/to/project/
or you can reference typescriptServices.js in your IDE.
Now reflection.d.ts, which contains all meta-interfaces, is included in lib.d.ts; if your IDE supports it, you can point to this file which contains Reflection definitions, too. I tested this with the latest release of Atom (using atom-typescript plugin), and it works well.
Note: unfortunately, this version seems not to work with Visual Studio 2015. Currently it includes the 1.8.x branch of the compiler, maybe we have to wait for 2.x compatibility.
Open tsconfig.json and add "reflectionEnabled": true, like the following snippet:
{
"compilerOptions": {
"noImplicitAny": true,
"removeComments": false
},
"files": [
"src/main.ts"
],
"reflectionEnabled": true
}
In one of your typescript files, create an interface and a class that implements it like the following:
interface MyInterface {
doSomething(what: string): number;
}
class MyClass implements MyInterface {
counter = 0;
doSomething(what: string): number {
console.log('Doing ' + what);
return this.counter++;
}
}
now let's print some useful things about MyClass...
let c: Class = MyClass.getClass();
for (let int of c.implements) {
console.log('Implemented interface: ' + int.name)
}
for (let member of c.members) {
console.log("Member name: " + member.name + " - member kind: " + member.type.kind);
}
compile with reflec-ts, launch it and, voilà!
$ node main.js
Implemented interface: MyInterface
Member name: counter - member kind: number
Member name: doSomething - member kind: function
now let's build an instance of MyClass from its metadata...
let c: Class = MyClass.getClass();
let ctor = c.getConstructor<any>(); //you may use an interface instead of <any> ;)
let myObj = new ctor();
console.log('myObj instanceof MyClass: ' + (myObj instanceof MyClass));
myObj.doSomething('nothing :)');
launch it, and... yeah!!
$ node main.js
myObj instanceof MyClass: true
Doing nothing :)
There are a few limitations, some of them are by design, others may be overcome in the future.
tsconfig.json, it cannot be enabled with command line parameters.--outFile is not supported.I'm defining the roadmap right now, the project will evolve to support full reflection capabilities and modularity. At the moment, there are some things that have to be completed soon:
This project is derived from the TypeScript project, but it is not officially supported by Microsoft. See LICENSE for details.
FAQs
TypeScript compiler with Reflection capabilities
We found that reflec-ts 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
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.