To create predefined types, such as mapping number
in TypeScript to Int
in Swift, we need to:
-
Create a TypeScript interface or type alias. Example:
type CodeGen_Int = number;
-
Specify this custom type in the configuration file. Example:
"parsing": { "predefinedTypes": [ "CodeGen_Int" ]
-
Make sure the mapping is also defined for the target language renderer. Example:
"rendering": { "swift": { "typeNameMap": { "CodeGen_Int": "Int" }
For full example, please refer to https://github.com/microsoft/ts-codegen/blob/main/demo/basic/config.json.