# 引入类型

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/go/llms.txt).

引入类型   重构会从类型表达式创建命名类型，如匿名 struct 类型。

例如，请考虑以下 JSON：

```JSON
{
"email": "noah.poulsen@example.com",
"gender": "male",
"phone_number": "53705244",
"birthdate": 1314124015,
"location": {
    "street": "7998 oddenvej",
    "city": "nr åby",
    "state": "syddanmark",
    "postcode": 73617
},
"username": "purplesnake503",
"password": "zelda",
"first_name": "noah",
"last_name": "poulsen",
"title": "mr",
"picture": "men/41.jpg"
}
```

将 JSON 粘贴到编辑器中，并将其转换为 struct 类型。 生成的  `T`  struct 包含一个名称为  `位置`  的字段，该字段具有匿名 struct 类型。 使用该重构将该匿名类型提取为命名类型。 该字段仍为具有名称的字段；这不会嵌入类型。

[Video](https://resources.jetbrains.com/help/img/idea/2026.3/go_extract_type_refactoring.mp4)

Procedure:

1. 在编辑器中，点击您想要提取的类型。

2. 点击  `重构 | 提取/引入` 并选择   引入类型  。

动画展示了 GoLand 如何将匿名结构类型转换为命名类型。 您可以使用以下代码片段尝试   引入类型   重构。

```GO
package main

func main() {
	_ = struct {
		Field1 string
		Field2 int
	}{
		Field1: "Hello",
		Field2: 42,
	}
}

```

[Video](https://resources.jetbrains.com/help/img/idea/2026.3/go_anonymous_structure_type_to_named_type.mp4)

