@@ -61,22 +61,16 @@ export function getResultNameFromMethod(method: string) {
6161 return `${ type } Result` ;
6262}
6363
64- function verifyTypeExist (
65- file : SourceFile ,
66- resultName : string ,
67- cause ?: unknown ,
68- ) : void {
64+ function doesTypeExist ( file : SourceFile , resultName : string ) : boolean {
6965 // Usually we get something like `BrowsingContext.GetTreeResult`
7066 let typeExist = getTypeInNamespace ( file , resultName ) ;
7167
7268 if ( ! typeExist ) {
7369 // Maybe it was not inside an Namespace try on the module scope
74- typeExist = file . getTypeAliasOrThrow ( resultName ) ;
70+ typeExist = file . getTypeAlias ( resultName ) ;
7571 }
7672
77- if ( ! typeExist ) {
78- throw new Error ( `Expected type ${ resultName } to exist` , { cause : cause } ) ;
79- }
73+ return typeExist !== undefined ;
8074}
8175
8276export function getResultWithFallbacks (
@@ -87,26 +81,23 @@ export function getResultWithFallbacks(
8781) {
8882 let resultName = params . replace ( 'Parameters' , 'Result' ) ;
8983
90- try {
91- try {
92- // Extensible exist, but does not give the correct type
93- // We need to infer from methods
94- if ( params . includes ( 'Extensible' ) ) {
95- resultName = getResultNameFromMethod ( method ) ;
96- }
84+ // Extensible exist, but does not give the correct type
85+ // We need to infer from methods
86+ if ( params . includes ( 'Extensible' ) ) {
87+ resultName = getResultNameFromMethod ( method ) ;
88+ }
9789
98- verifyTypeExist ( file , resultName ) ;
99- } catch ( error ) {
100- resultName = getResultNameFromMethod ( method ) ;
101- verifyTypeExist ( file , resultName , error ) ;
90+ if ( ! doesTypeExist ( file , resultName ) ) {
91+ resultName = getResultNameFromMethod ( method ) ;
92+ if ( ! doesTypeExist ( file , resultName ) ) {
93+ console . warn (
94+ `Warning: could not find result type for ${ method } (params: ${ params } ), defaulting to EmptyResult` ,
95+ ) ;
96+ // The EmptyResult is only available on the main spec
97+ spec = MAIN_SPEC_PREFIX ;
98+ // Default to EmptyResult
99+ resultName = `EmptyResult` ;
102100 }
103- } catch ( error ) {
104- console . log ( `No result type found` , error ) ;
105-
106- // The EmptyResult is only available on the main spec
107- spec = MAIN_SPEC_PREFIX ;
108- // Default to EmptyResult
109- resultName = `EmptyResult` ;
110101 }
111102
112103 if ( ! resultName . endsWith ( 'Result' ) ) {
0 commit comments