1
文字列にいくつかのロジックを保存しました。実行可能な関数に変換する必要があります。私はそれがTypescriptで強く型付けされるようにInterfaceが既にセットアップされていますが、うまくいかないようです。Typescript:インタフェースを持つ文字列から関数を作成
interface IInterface {
Run(data: string): Promise<string>;
}
let code: string = `
return new class{
let Run = function(data) {
console.log(data);
return "SUCCESS";
};
}
`;
let obj: IInterface = Function(code) as IInterface;
obj.Run("Test ").then((result: string) => {
console.log(result);
});
は書くべき:テストSUCCESS
実際のテキストは実際のJavaScriptと同じように使用するか、構文を変更することができますか? –
構文を変更することができます、私はちょうどいくつかのテストコードを書いています。 – Bill