Introduce type
The Introduce Type refactoring creates a named type from a type expression, such as an anonymous struct type.
For example, consider the following 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"
}
Paste the JSON into the editor and convert it to a struct type. The resulting T struct has a named Location field with an anonymous struct type. Use the refactoring to extract that anonymous type into a named type. The field remains a named field; this does not embed a type.
In the editor, click a type that you want to extract.
Click and select Introduce Type.
The animation shows how GoLand converts the anonymous structure type to a named type. You can try the Introduce Type refactoring with the following code snippet.
package main func main() { _ = struct { Field1 string Field2 int }{ Field1: "Hello", Field2: 42, } }
22 September 2026