-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: 模板字面量类型 | ||
date: 2025-01-17T15:27:56.070Z | ||
duration: 1min | ||
--- | ||
|
||
## 模板字面量类型(Template Literal Types) | ||
|
||
模板字面量类型是 TypeScript 中的一种类型,它允许你创建可以包含变量的字符串类型。 | ||
|
||
```ts | ||
type World = "world"; | ||
type Greeting = `hello ${World}`; // "hello world" | ||
``` | ||
|
||
```ts | ||
type EmailLocaleIDs = "welcome_email" | "email_heading"; | ||
type FooterLocaleIDs = "footer_title" | "footer_sendoff"; | ||
|
||
type AllLocaleIDs = `${EmailLocaleIDs | FooterLocaleIDs}_id`; | ||
// "welcome_email_id" | "email_heading_id" | "footer_title_id" | "footer_sendoff_id" | ||
``` | ||
|
||
## 相关文章 | ||
|
||
- https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html |