惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Latest news
Latest news
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
V
V2EX
博客园 - 司徒正美
B
Blog RSS Feed
AWS News Blog
AWS News Blog
MyScale Blog
MyScale Blog
Scott Helme
Scott Helme
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
NISL@THU
NISL@THU
博客园 - Franky
P
Proofpoint News Feed
博客园_首页
C
CERT Recently Published Vulnerability Notes
雷峰网
雷峰网
S
Schneier on Security
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
WordPress大学
WordPress大学
The Hacker News
The Hacker News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
Engineering at Meta
Engineering at Meta
罗磊的独立博客
T
The Blog of Author Tim Ferriss
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
SecWiki News
SecWiki News
云风的 BLOG
云风的 BLOG
美团技术团队
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Latest
Security Latest
C
Cyber Attacks, Cyber Crime and Cyber Security
B
Blog
S
Security Affairs

Deno

Deno 2.8 | Deno Claw Patrol: an open-source security firewall for agents | Deno Fresh 2.3: Zero JS by default, View Transitions, and Temporal support | Deno Deno 2.7: Temporal API, Windows ARM, and npm overrides | Deno Build a dinosaur runner game with Deno, pt. 6 | Deno Build a dinosaur runner game with Deno, pt. 5 | Deno Deno Deploy is Generally Available | Deno Introducing Deno Sandbox | Deno Build a dinosaur runner game with Deno, pt. 4 | Deno Build a dinosaur runner game with Deno, pt. 3 | Deno Build a dinosaur runner game with Deno, pt. 2 | Deno React / Next.js Denial-of-Service Vulnerability: Deno Deploy users protected | Deno Deno 2.6: dx is the new npx | Deno Build a dinosaur runner game with Deno, pt. 1 | Deno React Server Functions / Next.js Vulnerability: Deno Deploy users protected | Deno My highlights from the new Deno Deploy | Deno Deno's Other Open Source Projects | Deno How Deno protects against npm exploits | Deno Help Us Raise $200k to Free JavaScript from Oracle | Deno Deno 2.5: Permissions in the config file | Deno Fresh 2.0 Graduates to Beta, Adds Vite Support | Deno Deno 2.4: deno bundle is back | Deno JavaScript™ Trademark Update | Deno What's coming to JavaScript | Deno A brief history of JavaScript | Deno Reports of Deno's Demise Have Been Greatly Exaggerated | Deno An Update on Fresh | Deno How Plaid migrated 100 services to a new database platform 5x faster with Deno | Deno Deno 2.3: Improved deno compile, local npm packages, and more | Deno Add JSR packages with pnpm and Yarn | Deno Zero-config Debugging with Deno and OpenTelemetry | Deno Exploring Art with TypeScript, Jupyter, Polars, and Observable Plot | Deno Deno v Oracle Update 3: Fighting the JavaScript Trademark | Deno Build a custom RAG AI agent in TypeScript and Jupyter | Deno How to get deep traces in your Node.js backend with OTel and Deno | Deno toranoana.deno #20 登録受付中(2025年3月14日) | Deno Node just added TypeScript support. What does that mean for Deno? | Deno The Dino 🦕, the Llama 🦙, and the Whale 🐋 | Deno Publish a lint rule, get a prize | Deno Deno 2.2: OpenTelemetry, Lint Plugins, node:sqlite | Deno If you're not using npm specifiers, you're doing it wrong | Deno How Deno's documentation is evolving | Deno Oracle justified its JavaScript trademark with Node.js—now it wants that ignored | Deno Introducing the JSR open governance board | Deno Intro to Wasm in Deno | Deno Announcing OpenAI on JSR | Deno Deno in 2024 | Deno Goodbye WinterCG, welcome WinterTC | Deno Build a SolidJS app with Deno | Deno Run your Next.js SSR app on Deno Deploy | Deno Solve Advent of Code 2024 with Deno and Win Prizes! | Deno Deno v. Oracle: Canceling the JavaScript Trademark | Deno Deno 2.1: Wasm Imports and other enhancements | Deno Build a Typesafe API with tRPC and Deno | Deno Self-contained Executable Programs with Deno Compile | Deno Build a Database App with Drizzle ORM and Deno | Deno Introducing your new JavaScript package manager: Deno | Deno Announcing Growthbook on JSR | Deno Build an Astro site with Deno | Deno How to convert CommonJS to ESM | Deno Announcing Deno 2 | Deno The Final Touches: What’s New In v2.0.0-rc.10 | Deno Announcing Stable V8 Bindings for Rust | Deno Deno 2.0 Release Candidate | Deno Secure, efficient private npm registries with Cloudsmith and Deno | Deno Painting the Plane as We Fly It: Designing JSR | Deno Introducing Web Cache API support on Deno Deploy | Deno Deno 1.46: The Last 1.x Release | Deno Protect your cloud spend with new Deno Deploy spend limits | Deno What we got wrong about HTTP imports | Deno Benchmarking AWS Lambda Cold Starts Across JavaScript Runtimes | Deno Announcing Supabase on JSR | Deno Deno 1.45: Workspace and Monorepo Support | Deno Introducing KV Backup for Deno Subhosting | Deno A Gentle Intro to TypeScript | Deno Announcing Hono on JSR | Deno How We Made the Deno Language Server Ten Times Faster | Deno How the Guardian uses Deno to audit accessibility and performance across their 2.7 million articles | Deno Introducing More Flexible Domain Association for Deno Subhosting | Deno The stabilization process of the Standard Library has begun | Deno Deno 1.44: Private npm registries, improved Node.js compat, and performance boosts | Deno How we built a secure, performant, multi-tenant cloud platform to run untrusted code | Deno The Deno Standard Library is now available on JSR | Deno How to document your JavaScript package | Deno Your Low Code Solution Needs an Escape Hatch | Deno Deno 1.43: Improved Language Server performance | Deno How Slack used Deno to save months of engineering effort in launching their new platform | Deno JSR Is Not Another Package Manager | Deno Announcing the Hookdeck SDK on JSR | Deno Announcing the Neon Serverless Driver on JSR | Deno How we built JSR | Deno How Netlify used Deno Subhosting to build a successful edge functions product | Deno Introducing Simpler Project Creation in Deno Deploy | Deno Deno 1.42: Better dependency management with JSR | Deno Introducing deployctl, the command line interface for Deno Deploy | Deno Introducing JSR - the JavaScript Registry | Deno How to add Monaco to a Next.js app and securely run untrusted user code | Deno Survey Results and Roadmap | Deno Deno 1.41: smaller deno compile binaries | Deno Webhooks suck, but here are alternatives | Deno
An intro to TSConfig for JavaScript Developers | Deno
Jo Franchett · 2024-04-17 · via Deno

JavaScript is constantly evolving, from its roots as a simple scripting language into a robust, modern tool for building complex applications. To manage larger, complicated code bases, JavaScript developers are constantly looking for ways to improve their workflows, their code quality and productivity. TypeScript is a major innovation towards improving code quality and maintenance by adding types, so it’s no surprise that it’s one of the fastest growing languages.

TypeScript can feel scary if you’ve never used a compiled language or a compiler before. Or maybe you have, and you encountered a complex tsconfig.json file that you didn’t completely understand. This blog post is an introduction to TypeScript (TS) and how to configure your project to use TypeScript with ease:

  • From JS to TS
  • TSConfig settings
    • compilerOptions
    • Other TSConfig settings
  • Additional features and capabilities of TSConfig
  • What’s next

🚨️ Want to write and run TypeScript without any config? 🚨️

Deno natively supports TypeScript. Simply create a .ts file and run deno run yourfile.ts.

From JS to TS

TypeScript is built on top of JavaScript. It’s a superset — any valid JavaScript is valid TypeScript. If you’re new to TypeScript, it’s easy to think of it as a “super powered linter”, adding new features to the language to help you write JavaScript safely. It is designed to be strictly additive — TypeScript with the types stripped out is just JavaScript, but with types present, you get a much improved tooling, debugging and general developer experience.

Because the JavaScript ecosystem has grown organically over time, TypeScript aims to fit in with your existing tooling. Modern editors, build tools, package managers, testing frameworks and CI/CD tools all integrate with TypeScript. In order to adopt TypeScript, and tailor it to your specific project requirements and tools, you will need to configure the TypeScript compiler. This can be done using a file called tsconfig.json.

If you’re doing TypeScript for the first time in a new codebase, you will probably leave most of the options in tsconfig.json as default. For projects with tooling that needs interop, or has particular quirks, tsconfig.json offers all the leavers you may need to pull to interact with your ecosystem.

TSConfig settings

The tsconfig.json file allows you to configure how the TypeScript compiler processes your TypeScript code. The tsconfig.json file is just a JSON object with properties that define your compiler options and project settings. We’ll go through some of the properties you’re likely to need when setting up your own tsconfig.json file.

The first property to take a look at is compilerOptions, where you specify compiler settings.

Compiler settings in compilerOptions

The compilerOptions property is where you define TypeScript compiler settings. These options include -

target - Specifies the ECMAScript target version for the emitted JavaScript. Defaults to ES3. To ensure maximum compatibility, set this to the lowest version that your code requires to run. ESNext setting allows you to target the latest supported proposed features.

module - Defines the module system to use (CommonJS, AMD, ES6, etc.). Usage depends on your project’s requirements and the environment that your code will run in. Most modern projects will use ES6 or ESNext.

outDir - Specifies the output directory for compiled JavaScript files. Usually set to dist to create a dist directory for your compiled files.

strict - Enables strict type-checking options to help catch errors in your code. Set to true for strict type checking.

alwaysStrict - Automatically set to true if strict is enabled, this parses the code in JavaScript strict mode and emits use strict for each source file.

esModuleInterop - In JavaScript, there are two main module systems: ECMAScript modules (ESM) and CommonJS modules (CJS). They have different syntax and semantics for imports and exports. When working in a TypeScript project that uses both ESM and CJS modules, setting esModuleInterop to true ensures that TypeScript handles imports and exports in a way that is compatible with both module systems. This is recommended if you are working with third party libraries that use both CJS and ESM.

lib - Specifies the libraries to include when type-checking. TypeScript includes type declarations (type definitions) for JavaScript built-in objects, such as Array, String, Promise, etc. These declarations define the shape and behavior of these objects, allowing TypeScript to provide accurate type checking and IntelliSense support. By default, TypeScript includes a standard set of library declarations (dom, es5, es6, etc.) based on the ECMAScript version targeted by your project. However, you can customize the included libraries using the “lib” option to match your project’s environment more precisely. For example, if you’re targeting only Node.js, you might exclude browser-specific declarations like dom.

sourceMap - Generates source map files (.map) to aid debugging. Source maps are files that map the generated JavaScript code back to its original TypeScript source code. When using debugging tools, source maps allow you to set breakpoints, inspect variables, and step through your TypeScript code as if you were debugging the original TypeScript source. Set to true to enable the use of source maps.

Other settings that may be useful:

jsx - If you are using JSX (for example with React), this setting determines how your JSX files should be treated (preserve, react, react-native, etc.).

removeComments - Strips comments from your compiled code. Helpful if minifying your compiled code.

sourceRoot - Specifies the location where your debugger should locate TypeScript files instead of source locations. Use this flag if the sources located at run-time are in a different location than that at design-time. The location specified will be embedded in the source map to direct your debugger.

Other TSConfig settings

include - specifies an array of file paths or glob patterns that TypeScript should include in the compilation process. Only files matching the specified patterns will be considered for compilation. You can use glob patterns (e.g., “src/**/*.ts”) to include files from specific directories or with specific file extensions. If include is not specified, TypeScript includes all .ts, .tsx, and .d.ts files in the project directory by default.

exclude - This setting specifies an array of file paths or glob patterns that TypeScript should exclude from the compilation process (even if they match the patterns specified in the include setting). You can use exclude to ignore files or directories that you don’t want to be compiled, such as test files, build artifacts, or third-party libraries. Usually you will want to exclude your node_modules folder.

Additional features and capabilities of TSConfig

Declaration Maps - TypeScript can generate declaration map files (.d.ts.map) alongside declaration files (.d.ts) if declarationMap is set to true in your tsconfig.json. Declaration maps serve a similar purpose to source maps but are specific to TypeScript declaration files. These declaration maps provide mappings between the generated declaration files and their corresponding source map files, aiding in debugging and providing better tooling support.

Watch Mode - TypeScript’s watch mode tsc --watch monitors changes to your TypeScript files and automatically recompiles them whenever they’re modified. This is useful during development, as it speeds up the feedback loop and eliminates the need to manually trigger compilation after each change.

Incremental Builds - TypeScript’s incremental builds feature keeps track of changes to your project’s files and dependencies, allowing it to only rebuild the parts of your project that have changed since the last compilation. This can improve compilation times for large projects.

Override Options - You can override specific compiler options for individual files or sets of files using comment directives in your TypeScript source files. For example, you can disable certain strict checks with // @ts-ignore or specify custom compiler options with// @ts-nocheck for specific sections of code.

Use your tsconfig.json tile as a gateway to unlock the full potential of TypeScript in your projects. By understanding its purpose and leveraging its capabilities, you can embrace TypeScript with confidence, and gain a more reliable, efficient, and enjoyable development experience.

To get you started there is a community owned repository of TSConfig base files for your chosen runtime, then all you need to focus on is the unique choices for your project.

What’s next?

More and more developers are using TypeScript to build higher quality code bases and be more productive. Hopefully, this post demystifies setting up a new TypeScript project using tsconfig.json.

However, if you’re interested in diving into TypeScript without having to do any configuration, Deno supports TypeScript natively. Simply create a .ts file, write some types, and run it immediately with deno run your_file.ts.