diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-01-14 10:37:51 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-01-14 10:43:20 +0530 |
| commit | efe0ab336144d2d965bf355db02762f5cf539c7f (patch) | |
| tree | 5447c661ffed03e833d7283d3b174bb22fdd2e7a /src | |
| parent | 2979eda13e25725683aa10292b31f22793c4e0c0 (diff) | |
| download | ts-types-lang-efe0ab336144d2d965bf355db02762f5cf539c7f.tar.gz ts-types-lang-efe0ab336144d2d965bf355db02762f5cf539c7f.zip | |
feat: adds func to try/catch
Diffstat (limited to 'src')
| -rw-r--r-- | src/eval-env/builtins.ts | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/eval-env/builtins.ts b/src/eval-env/builtins.ts index f67fcc6..ed94943 100644 --- a/src/eval-env/builtins.ts +++ b/src/eval-env/builtins.ts @@ -31,7 +31,12 @@ const applyFunc = (ctx: Ctx, fn: Type | undefined, val: string): Type => { const typeParameters = functionNode.getTypeParameters() ?? [] if (typeParameters.length > 0) { - typeParameters[0]?.getConstraint()?.replaceWithText(val) + const constraint = typeParameters[0]?.getConstraint() + if (constraint) { + constraint?.replaceWithText(val) + } else { + typeParameters[0]?.setConstraint(val) + } } return resValueNode?.getType() @@ -126,9 +131,7 @@ export default (ctx: Ctx, args: Type[]) => ({ const resultType = applyFunc(ctx, chainToKind, `(${ctx.getResultExpr(resultKey)})['output']`) - const res = await ctx.evaluateType(ctx, resultType) - - return res + return ctx.evaluateType(ctx, resultType) }, Try: async () => { @@ -139,11 +142,8 @@ export default (ctx: Ctx, args: Type[]) => ({ return await ctx.evaluateType(ctx, effTyp) } catch (e) { const error = JSON.stringify((e as any)?.message ?? e) - const catchResExpr = `(${ctx.typeToString( - catchK - )} & { input: ${error} })['return']` - const [resultKey, _] = ctx.createResult(catchResExpr) - return [resultKey] + const resultType = applyFunc(ctx, catchK, error) + return ctx.evaluateType(ctx, resultType) } }, |
