ImportTypeScript API + get value of `compilerOptions` with default options from `tsconfig.json`?
Hello, I'm trying to figure out the proper way to do a few things:
1. What's the correct way to import the TypeScript API in Deno? At the moment, I'm importing from npm because I can't find any official TypeScript module in Deno.
2. What's the best way to read the compilerOptions
tsconfig.json
such that anything not set gets its default value? On a cursory glance, it would see like I can easily import the JSON, and I would feed it to convertCompilerOptionsFromJson
, but I have no idea how to import, which is also why I'm asking 1.
Even if this is an XY problem, I think that learning about the import maps and Deno ecosystem is worthwhile.2 Replies
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, I can provide some general advice:
1. In Deno, you typically wouldn't import the TypeScript API from npm. Deno has its own TypeScript compiler built-in, and it's not designed to use npm modules out of the box. If you need to interact with TypeScript in Deno, you would generally do so through Deno's own APIs. For example, Deno provides
Deno.compile
and Deno.transpileOnly
functions for compiling and transpiling TypeScript code.
2. As for reading compilerOptions
from a tsconfig.json
file, Deno does not currently provide a built-in way to parse tsconfig.json
files and apply the default TypeScript compiler options. You would typically handle the tsconfig.json
file as a regular JSON file using Deno's standard file reading and JSON parsing capabilities. However, applying the default TypeScript compiler options to the parsed JSON object is not something that Deno's standard library handles, and you might need to use TypeScript's own functions for that, which are not directly exposed by Deno.
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. If you need to work with TypeScript compiler options in a way that requires TypeScript's own API, you might need to consider other approaches or workarounds that fit within Deno's capabilities and constraints.Is there a way to get the default compiler options?
I found this at https://deno.land/std@0.39.0/manual.md?source=.