Skip to content

Commit d4e0fd7

Browse files
author
Keegan S
authored
Add Option type for NULL fields (#263)
* Add NullableOption type for nullable fields on entities and complex types * Check if field is `null`-able before emitting `Option` Thank you @meme
1 parent 864f07f commit d4e0fd7

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Templates/TypeScript/src/entity_types.ts.tt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
export as namespace microsoftgraph;
2727

28+
type NullableOption<T> = T | null;
29+
2830
<#
2931
foreach(var enumType in enumTypes) {
3032
var enumTypeName = enumType.Name.UpperCaseFirstChar();
@@ -100,7 +102,17 @@ export interface <#= entityTypeName #><#
100102
}
101103
}
102104
#>
103-
<#= prop.Name #>?: <#= prop.GetTypeString() #>;
105+
<#
106+
if(prop.IsNullable) {
107+
#>
108+
<#= prop.Name #>?: NullableOption<<#= prop.GetTypeString() #>>;
109+
<#
110+
} else {
111+
#>
112+
<#= prop.Name #>?: <#= prop.GetTypeString() #>;
113+
<#
114+
}
115+
#>
104116
<#
105117
}
106118
#>
@@ -161,7 +173,17 @@ export interface <#= complexTypeName #><#
161173
}
162174
}
163175
#>
164-
<#= prop.Name #>?: <#= prop.GetTypeString() #>;
176+
<#
177+
if(prop.IsNullable) {
178+
#>
179+
<#= prop.Name #>?: NullableOption<<#= prop.GetTypeString() #>>;
180+
<#
181+
} else {
182+
#>
183+
<#= prop.Name #>?: <#= prop.GetTypeString() #>;
184+
<#
185+
}
186+
#>
165187
<#
166188
}
167189
#>

0 commit comments

Comments
 (0)