You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(ts-interface-generator): fix crash with parent w/o settings type
To generate constructor signatures, a settings type needs to be created
which inherits from the
parent class' settings type and adds the properties, aggregations etc.
of the current class. This
rightly leads to an error. But this should not lead to an error when the
class does not add any API
items at all.
related to #346
Copy file name to clipboardExpand all lines: packages/ts-interface-generator/src/interfaceGenerationHelper.ts
+55-42
Original file line number
Diff line number
Diff line change
@@ -114,7 +114,7 @@ function getManagedObjects(
114
114
thrownewError(
115
115
"Type '"+
116
116
typeNode.getText()+
117
-
"' in "+
117
+
"' referenced in "+
118
118
sourceFile.fileName+
119
119
" could not be resolved - are the UI5 (and other) type definitions available and known in the tsconfig? Or is there a different reason why this type would not be known?"
120
120
);
@@ -130,7 +130,45 @@ function getManagedObjects(
130
130
}
131
131
managedObjectFound=true;
132
132
133
-
// ok, we have a ManagedObject/Control; now check whether there is a settings type in the superclass
133
+
// ok, we have a ManagedObject/Control; now check whether it contains a metadata section, which means that accessor methods need to be generated
`Class ${statement.name ? statement.name.text : ""} in ${
153
+
sourceFile.fileName
154
+
} inherits from ${interestingBaseClass} but has no metadata. This is not necessarily an issue, but if there is a metadata member in this class which *should* be recognized, make sure it has the 'static' keyword!`
155
+
);
156
+
return;
157
+
}elseif(metadata.length>1){
158
+
// no metadata? => nothing to do
159
+
log.warn(
160
+
`ManagedObject with ${
161
+
metadata.length
162
+
} static metadata members in class ${
163
+
statement.name ? statement.name.text : ""
164
+
} inside ${
165
+
sourceFile.fileName
166
+
}. This is unexpected. Ignoring this class.`
167
+
);
168
+
return;
169
+
}
170
+
171
+
// now check whether there is a settings type in the superclass
134
172
// (which the generated settings type needs to inherit from)
135
173
// There really should be, because all descendants of ManagedObject should have one!
136
174
letsettingsTypeFullName;
@@ -141,13 +179,22 @@ function getManagedObjects(
141
179
constsymbol=settingsType.getSymbol();
142
180
settingsTypeFullName=
143
181
typeChecker.getFullyQualifiedName(symbol);
144
-
}else{
182
+
}elseif(metadata){
145
183
thrownewError(
146
184
`${
147
185
statement.name ? statement.name.text : ""
148
-
} inherits from ${interestingBaseClass} but the parent class ${typeChecker.getFullyQualifiedName(
186
+
} inherits from ${interestingBaseClass}and has metadata but the parent class ${typeChecker.getFullyQualifiedName(
149
187
type.getSymbol()
150
-
)} seems to have no settings type`
188
+
)} seems to have no settings type. It might have no constructors, this is where the settings type is used.
189
+
190
+
In case this parent class is also in your project, make sure to add its constructors, then try again. A comment with instructions might be in the console output above.
191
+
Otherwise, you can temporarily remove this file (${
192
+
sourceFile.fileName
193
+
}) from the project and try again to get the console output with the suggested constructors.
194
+
In any case, you need to make the parent parent class ${typeChecker.getFullyQualifiedName(
195
+
type.getSymbol()
196
+
)} have constructors with typed settings object to overcome this issue.
`ManagedObject with no metadata in class ${className} inside ${fileName}. This is not necessarily an issue, but if there is a metadata member in this class which *should* be recognized, make sure it has the 'static' keyword!`
416
-
);
417
-
return;
418
-
}elseif(metadata.length>1){
419
-
// no metadata? => nothing to do
420
-
log.warn(
421
-
`ManagedObject with ${metadata.length} static metadata members in class ${className} inside ${fileName}. This is unexpected. Ignoring this class.`
422
-
);
423
-
return;
424
-
}
425
-
426
-
if(!metadata[0].initializer){
427
-
log.warn(
428
-
`Class ${className} inside ${fileName} has a static metadata member without initializer. Please assign the metadata object immediately to have an interface generated for the API. Write: 'static readonly metadata = { ... }'`
429
-
);
430
-
return;
431
-
}
432
445
433
446
// by now we have something that looks pretty much like a ManagedObject metadata object
0 commit comments