lyhokia
lyhokia
DDeno
Created by lyhokia on 3/5/2024 in #help
How to rewrite this code so I don't have to force deno to stop linting?
import { parse } from "https://deno.land/std@0.218.2/toml/mod.ts";
import { match } from "npm:ts-pattern@5.0.8";
// suppose options.config might be either string or undefined
const readToml = match(options.config)
.with(P.string, async (configPath) => {
return parse(await Deno.readTextFile(configPath));
})
// deno-lint-ignore require-await
.with(undefined, async () => ({}))
.exhaustive();
console.log(await readToml);
import { parse } from "https://deno.land/std@0.218.2/toml/mod.ts";
import { match } from "npm:ts-pattern@5.0.8";
// suppose options.config might be either string or undefined
const readToml = match(options.config)
.with(P.string, async (configPath) => {
return parse(await Deno.readTextFile(configPath));
})
// deno-lint-ignore require-await
.with(undefined, async () => ({}))
.exhaustive();
console.log(await readToml);
So here I'm matching and generating 2 promises. However the second promise is not necessary. Is there a way I can just generate the value? I tried to remove 2 asyncs and push up the async to outer function but that doesn't seem to work because await in a nested function is not allowed.
3 replies