- Notifications
You must be signed in to change notification settings - Fork4
Typescript Transform Macros
License
NotificationsYou must be signed in to change notification settings
LeDDGroup/typescript-transform-macros
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Typescript Transform Macros
Examples fromhttps://github.com/codemix/babel-plugin-macros.
npm install --save-dev typescript-transform-macros
Usage withttypescript
Add it toplugins in yourtsconfig.json
{"compilerOptions": {"plugins": [{"transform":"typescript-transform-macros" }] }}Also declare globally theMACRO function:
declarefunctionMACRO<T>(t:T):T;
Input:
declarefunctionMACRO<T>(t:T):T;constMAP=MACRO(<T,L>(inputConst:T[],visitor:(value:T,index?:number,input?:T[])=>L)=>{constinput=inputConst;constlength=input.length;constresult=newArray(length)asL[];for(leti=0;i<length;i++){result[i]=visitor(input[i],i,input);}returnresult;});declareinterfaceArray<T>{MAP:Array<T>["map"];}console.log([1,2,3].MAP(n=>3*n+1));
Output:
"use strict";constinput_1=[1,2,3];constlength_1=input_1.length;constresult_1=newArray(length_1);for(leti_1=0;i_1<length_1;i_1++){result_1[i_1]=3*input_1[i_1]+1;}console.log(result_1);//> [ 4, 7, 10 ]
About
Typescript Transform Macros
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.