From 29d75505bf9ad1886ffbb80f348da9239b78c7fe Mon Sep 17 00:00:00 2001 From: Navya Singh Date: Wed, 21 Oct 2026 16:37:56 -0700 Subject: [PATCH] Correct Handbook content and sidebar heading hierarchy Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../copy/en/declaration-files/Publishing.md | 4 +- .../copy/en/handbook-v2/Everyday Types.md | 4 +- .../copy/en/handbook-v2/Modules.md | 12 +++--- .../copy/en/handbook-v2/Narrowing.md | 6 +-- .../Type Manipulation/Conditional Types.md | 4 +- .../Type Manipulation/Mapped Types.md | 2 +- .../Template Literal Types.md | 12 +++--- .../copy/en/javascript/JSDoc Reference.md | 8 ++-- .../documentation/copy/en/reference/Mixins.md | 4 +- .../copy/en/reference/Namespaces.md | 12 +++--- .../en/reference/Triple-Slash Directives.md | 4 +- .../copy/en/reference/Utility Types.md | 38 +++++++++---------- .../copy/en/tutorials/ASP.NET Core.md | 4 +- .../en/tutorials/Babel with TypeScript.md | 2 +- .../src/templates/documentation.scss | 2 +- .../src/templates/documentation.tsx | 4 +- 16 files changed, 61 insertions(+), 61 deletions(-) diff --git a/packages/documentation/copy/en/declaration-files/Publishing.md b/packages/documentation/copy/en/declaration-files/Publishing.md index ce0cd931ad65..22fc5beed01f 100644 --- a/packages/documentation/copy/en/declaration-files/Publishing.md +++ b/packages/documentation/copy/en/declaration-files/Publishing.md @@ -95,7 +95,7 @@ If your type definitions depend on another package: When TypeScript opens a `package.json` file to figure out which files it needs to read, it first looks at a field called `typesVersions`. -#### Folder redirects (using `*`) +### Folder redirects (using `*`) A `package.json` with a `typesVersions` field might look like this: @@ -121,7 +121,7 @@ If we import from `package-name/foo`, we'll try to look for `[...]/node_modules/ What if we're not running in TypeScript 3.1 in this example? Well, if none of the fields in `typesVersions` get matched, TypeScript falls back to the `types` field, so here TypeScript 3.0 and earlier will be redirected to `[...]/node_modules/package-name/index.d.ts`. -#### File redirects +### File redirects When you want to only change the resolution for a single file at a time, you can tell TypeScript the file to resolve differently by passing in the exact filenames: diff --git a/packages/documentation/copy/en/handbook-v2/Everyday Types.md b/packages/documentation/copy/en/handbook-v2/Everyday Types.md index 76ccbb9f5309..64f1856e3ef9 100644 --- a/packages/documentation/copy/en/handbook-v2/Everyday Types.md +++ b/packages/documentation/copy/en/handbook-v2/Everyday Types.md @@ -704,7 +704,7 @@ Enums are a feature added to JavaScript by TypeScript which allows for describin It's worth mentioning the rest of the primitives in JavaScript which are represented in the type system. Though we will not go into depth here. -#### `bigint` +### `bigint` From ES2020 onwards, there is a primitive in JavaScript used for very large integers, `BigInt`: @@ -720,7 +720,7 @@ const anotherHundred: bigint = 100n; You can learn more about BigInt in [the TypeScript 3.2 release notes](/docs/handbook/release-notes/typescript-3-2.html#bigint). -#### `symbol` +### `symbol` There is a primitive in JavaScript used to create a globally unique reference via the function `Symbol()`: diff --git a/packages/documentation/copy/en/handbook-v2/Modules.md b/packages/documentation/copy/en/handbook-v2/Modules.md index d84f9f9e7575..b97253ff5f36 100644 --- a/packages/documentation/copy/en/handbook-v2/Modules.md +++ b/packages/documentation/copy/en/handbook-v2/Modules.md @@ -201,7 +201,7 @@ type Animals = Cat | Dog; TypeScript has extended the `import` syntax with two concepts for declaring an import of a type: -###### `import type` +##### `import type` Which is an import statement which can _only_ import types: @@ -221,7 +221,7 @@ import type { createCatName } from "./animal.js"; const name = createCatName(); ``` -###### Inline `type` imports +##### Inline `type` imports TypeScript 4.5 also allows for individual imports to be prefixed with `type` to indicate that the imported reference is a type: @@ -258,7 +258,7 @@ You can learn more about this syntax in the [modules reference page](/docs/handb CommonJS is the format which most modules on npm are delivered in. Even if you are writing using the ES Modules syntax above, having a brief understanding of how CommonJS syntax works will help you debug easier. -#### Exporting +### Exporting Identifiers are exported via setting the `exports` property on a global called `module`. @@ -365,7 +365,7 @@ import { valueOfPi } from "./constants.js"; export const twoPi = valueOfPi * 2; ``` -#### `ES2020` +### `ES2020` ```ts twoslash // @showEmit @@ -376,7 +376,7 @@ import { valueOfPi } from "./constants.js"; export const twoPi = valueOfPi * 2; ``` -#### `CommonJS` +### `CommonJS` ```ts twoslash // @showEmit @@ -387,7 +387,7 @@ import { valueOfPi } from "./constants.js"; export const twoPi = valueOfPi * 2; ``` -#### `UMD` +### `UMD` ```ts twoslash // @showEmit diff --git a/packages/documentation/copy/en/handbook-v2/Narrowing.md b/packages/documentation/copy/en/handbook-v2/Narrowing.md index c7a552ecf9b9..39d2fc7022f9 100644 --- a/packages/documentation/copy/en/handbook-v2/Narrowing.md +++ b/packages/documentation/copy/en/handbook-v2/Narrowing.md @@ -483,7 +483,7 @@ In addition, classes can [use `this is Type`](/docs/handbook/2/classes.html#this Types can also be narrowed using [Assertion functions](/docs/handbook/release-notes/typescript-3-7.html#assertion-functions). -# Discriminated unions +## Discriminated unions Most of the examples we've looked at so far have focused around narrowing single variables with simple types like `string`, `boolean`, and `number`. While this is common, most of the time in JavaScript we'll be dealing with slightly more complex structures. @@ -701,12 +701,12 @@ From there, the type system was able to do the "right" thing and figure out the Discriminated unions are useful for more than just talking about circles and squares. They're good for representing any sort of messaging scheme in JavaScript, like when sending messages over the network (client/server communication), or encoding mutations in a state management framework. -# The `never` type +## The `never` type When narrowing, you can reduce the options of a union to a point where you have removed all possibilities and have nothing left. In those cases, TypeScript will use a `never` type to represent a state which shouldn't exist. -# Exhaustiveness checking +## Exhaustiveness checking The `never` type is assignable to every type; however, no type is assignable to `never` (except `never` itself). This means you can use narrowing and rely on `never` turning up to do exhaustive checking in a `switch` statement. diff --git a/packages/documentation/copy/en/handbook-v2/Type Manipulation/Conditional Types.md b/packages/documentation/copy/en/handbook-v2/Type Manipulation/Conditional Types.md index 5c5485796880..1ac6e5f684f5 100644 --- a/packages/documentation/copy/en/handbook-v2/Type Manipulation/Conditional Types.md +++ b/packages/documentation/copy/en/handbook-v2/Type Manipulation/Conditional Types.md @@ -106,7 +106,7 @@ let c = createLabel(Math.random() ? "hello" : 42); // ^? ``` -### Conditional Type Constraints +## Conditional Type Constraints Often, the checks in a conditional type will provide us with some new information. Just like narrowing with type guards can give us a more specific type, the true branch of a conditional type will further constrain generics by the type we check against. @@ -172,7 +172,7 @@ type Num = Flatten; When `Flatten` is given an array type, it uses an indexed access with `number` to fetch out `string[]`'s element type. Otherwise, it just returns the type it was given. -### Inferring Within Conditional Types +## Inferring Within Conditional Types We just found ourselves using conditional types to apply constraints and then extract out types. This ends up being such a common operation that conditional types make it easier. diff --git a/packages/documentation/copy/en/handbook-v2/Type Manipulation/Mapped Types.md b/packages/documentation/copy/en/handbook-v2/Type Manipulation/Mapped Types.md index d3416101908c..559f17b7cf9a 100644 --- a/packages/documentation/copy/en/handbook-v2/Type Manipulation/Mapped Types.md +++ b/packages/documentation/copy/en/handbook-v2/Type Manipulation/Mapped Types.md @@ -46,7 +46,7 @@ type FeatureOptions = OptionsFlags; // ^? ``` -### Mapping Modifiers +## Mapping Modifiers There are two additional modifiers which can be applied during mapping: `readonly` and `?` which affect mutability and optionality respectively. diff --git a/packages/documentation/copy/en/handbook-v2/Type Manipulation/Template Literal Types.md b/packages/documentation/copy/en/handbook-v2/Type Manipulation/Template Literal Types.md index 8ce0761f3ba0..f798941965a8 100644 --- a/packages/documentation/copy/en/handbook-v2/Type Manipulation/Template Literal Types.md +++ b/packages/documentation/copy/en/handbook-v2/Type Manipulation/Template Literal Types.md @@ -42,7 +42,7 @@ type LocaleMessageIDs = `${Lang}_${AllLocaleIDs}`; We generally recommend that people use ahead-of-time generation for large string unions, but this is useful in smaller cases. -### String Unions in Types +## String Unions in Types The power in template literals comes when defining a new string based on information inside a type. @@ -124,7 +124,7 @@ person.on("firstName", () => {}); person.on("frstNameChanged", () => {}); ``` -### Inference with Template Literals +## Inference with Template Literals Notice that we did not benefit from all the information provided in the original passed object. Given change of a `firstName` (i.e. a `firstNameChanged` event), we should expect that the callback will receive an argument of type `string`. Similarly, the callback for a change to `age` should receive a `number` argument. We're naively using `any` to type the `callback`'s argument. Again, template literal types make it possible to ensure an attribute's data type will be the same type as that attribute's callback's first argument. @@ -181,7 +181,7 @@ To help with string manipulation, TypeScript includes a set of types which can b Converts each character in the string to the uppercase version. -##### Example +#### Example ```ts twoslash type Greeting = "Hello, world" @@ -197,7 +197,7 @@ type MainID = ASCIICacheKey<"my_app"> Converts each character in the string to the lowercase equivalent. -##### Example +#### Example ```ts twoslash type Greeting = "Hello, world" @@ -213,7 +213,7 @@ type MainID = ASCIICacheKey<"MY_APP"> Converts the first character in the string to an uppercase equivalent. -##### Example +#### Example ```ts twoslash type LowercaseGreeting = "hello, world"; @@ -225,7 +225,7 @@ type Greeting = Capitalize; Converts the first character in the string to a lowercase equivalent. -##### Example +#### Example ```ts twoslash type UppercaseGreeting = "HELLO WORLD"; diff --git a/packages/documentation/copy/en/javascript/JSDoc Reference.md b/packages/documentation/copy/en/javascript/JSDoc Reference.md index 7f84959c1ee9..f4be61b905c5 100644 --- a/packages/documentation/copy/en/javascript/JSDoc Reference.md +++ b/packages/documentation/copy/en/javascript/JSDoc Reference.md @@ -13,7 +13,7 @@ Note: - Any tags which are not explicitly listed below (such as `@async`) are not yet supported. - Only documentation tags are supported in TypeScript files. The rest of the tags are only supported in JavaScript files. -#### Types +## Types - [`@type`](#type) - [`@import`](#import) @@ -25,7 +25,7 @@ Note: - [`@satisfies`](#satisfies) -#### Classes +## Classes - [Property Modifiers](#property-modifiers) `@public`, `@private`, `@protected`, `@readonly` - [`@override`](#override) @@ -34,7 +34,7 @@ Note: - [`@class`](#constructor) (or [`@constructor`](#constructor)) - [`@this`](#this) -#### Documentation +## Documentation Documentation tags work in both TypeScript and JavaScript. @@ -42,7 +42,7 @@ Documentation tags work in both TypeScript and JavaScript. - [`@see`](#see) - [`@link`](#link) -#### Other +## Other - [`@enum`](#enum) - [`@author`](#author) diff --git a/packages/documentation/copy/en/reference/Mixins.md b/packages/documentation/copy/en/reference/Mixins.md index 67518cc872bc..e8e929123545 100644 --- a/packages/documentation/copy/en/reference/Mixins.md +++ b/packages/documentation/copy/en/reference/Mixins.md @@ -213,7 +213,7 @@ This pattern relies less on the compiler, and more on your codebase to ensure bo The mixin pattern is supported natively inside the TypeScript compiler by code flow analysis. There are a few cases where you can hit the edges of the native support. -#### Decorators and Mixins [`#4881`](https://github.com/microsoft/TypeScript/issues/4881) +### Decorators and Mixins [`#4881`](https://github.com/microsoft/TypeScript/issues/4881) You cannot use decorators to provide mixins via code flow analysis: @@ -245,7 +245,7 @@ const playerTwo = (new Player() as unknown) as FreezablePlayer; playerTwo.shouldFreeze; ``` -#### Static Property Mixins [`#17829`](https://github.com/microsoft/TypeScript/issues/17829) +### Static Property Mixins [`#17829`](https://github.com/microsoft/TypeScript/issues/17829) More of a gotcha than a constraint. The class expression pattern creates singletons, so they can't be mapped at the type system to support different variable types. diff --git a/packages/documentation/copy/en/reference/Namespaces.md b/packages/documentation/copy/en/reference/Namespaces.md index 5ad3795b352d..ea4490a7880d 100644 --- a/packages/documentation/copy/en/reference/Namespaces.md +++ b/packages/documentation/copy/en/reference/Namespaces.md @@ -125,7 +125,7 @@ Even though the files are separate, they can each contribute to the same namespa Because there are dependencies between files, we'll add reference tags to tell the compiler about the relationships between the files. Our test code is otherwise unchanged. -##### Validation.ts +### Validation.ts ```ts namespace Validation { @@ -135,7 +135,7 @@ namespace Validation { } ``` -##### LettersOnlyValidator.ts +### LettersOnlyValidator.ts ```ts /// @@ -149,7 +149,7 @@ namespace Validation { } ``` -##### ZipCodeValidator.ts +### ZipCodeValidator.ts ```ts /// @@ -163,7 +163,7 @@ namespace Validation { } ``` -##### Test.ts +### Test.ts ```ts /// @@ -208,7 +208,7 @@ tsc --outFile sample.js Validation.ts LettersOnlyValidator.ts ZipCodeValidator.t Alternatively, we can use per-file compilation (the default) to emit one JavaScript file for each input file. If multiple JS files get produced, we'll need to use `