Skip to content
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

Transpile into Babel/tcomb syntax #5125

Closed
jednano opened this issue Oct 5, 2015 · 4 comments
Closed

Transpile into Babel/tcomb syntax #5125

jednano opened this issue Oct 5, 2015 · 4 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript

Comments

@jednano
Copy link
Contributor

jednano commented Oct 5, 2015

I know this is a stretch, but what if you could set a flag to transpile TS code into code that would be readable by babel-plugin-tcomb, which came out recently? This would enable runtime type checking, which I previously brought up in #1573, but it would require interfaces be transpiled into structs:

interface Point {
    x: number;
    y: number;
}

function foo(point: Point) {
    return point.x * point.y;
}

becomes...

import t from 'tcomb';

const Point = t.struct({
    x: t.Number,
    y: t.Number
});

function foo(point: Point) {
    return point.x * point.y;
}

If not provided directly by the compiler, the same could be achieved by a 3rd party module, if only a concrete syntax tree #625 were provided.

Related issues:

@jednano
Copy link
Contributor Author

jednano commented Oct 5, 2015

For the record, I already have node modules that transpile from TS into ES6 and then Babel transpiles it from there and it works great! If only this last missing piece of the puzzle were implemented, we would have an awesome solution for both compile time and runtime type checking!

@mhegazy
Copy link
Contributor

mhegazy commented Oct 21, 2015

I think this is an interesting and useful proposition. I would say the best way this can be implemented is as an emitter extension; we first need to allow for an extension point in the emitter to allow for additional transformations. @rbuckton has a change to make this doable today: #4010 and some helper factory functions in #3762.

@DanielRosenwasser
Copy link
Member

Related is #1573.

@mhegazy mhegazy added Suggestion An idea for TypeScript Out of Scope This idea sits outside of the TypeScript language design constraints Declined The issue was declined as something which matches the TypeScript vision labels Nov 13, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Nov 13, 2015

The TypeScript compiler should expose a transformation API that enable these scenarios. i do not think this belongs in the core though. We are working on enabling a plug-able emitter transformation system, so this, along with an extension should address the OP.

@mhegazy mhegazy closed this as completed Nov 13, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants