diff --git a/tools/hermes-parser/js/flow-api-translator/__tests__/flowToFlowDef-test.js b/tools/hermes-parser/js/flow-api-translator/__tests__/flowToFlowDef-test.js index afe7a89997d..9d25a6627a4 100644 --- a/tools/hermes-parser/js/flow-api-translator/__tests__/flowToFlowDef-test.js +++ b/tools/hermes-parser/js/flow-api-translator/__tests__/flowToFlowDef-test.js @@ -521,6 +521,12 @@ describe('flowToFlowDef', () => { `declare export class Foo extends X {}`, ); }); + it('extends as cast expression', async () => { + await expectTranslate( + `export class Foo extends (Bar as X) {}`, + `declare export class Foo extends X {}`, + ); + }); it('extends type cast typeof expression', async () => { await expectTranslate( `export class Foo extends (Bar: typeof X) {}`, diff --git a/tools/hermes-parser/js/flow-api-translator/src/flowToFlowDef.js b/tools/hermes-parser/js/flow-api-translator/src/flowToFlowDef.js index 6d7a05d9317..e2018329909 100644 --- a/tools/hermes-parser/js/flow-api-translator/src/flowToFlowDef.js +++ b/tools/hermes-parser/js/flow-api-translator/src/flowToFlowDef.js @@ -1047,8 +1047,12 @@ function convertSuperClass( context, ); } - case 'TypeCastExpression': { - const typeAnnotation = superClass.typeAnnotation.typeAnnotation; + case 'TypeCastExpression': + case 'AsExpression': { + const typeAnnotation = + superClass.type === 'TypeCastExpression' + ? superClass.typeAnnotation.typeAnnotation + : superClass.typeAnnotation; if (typeAnnotation.type === 'GenericTypeAnnotation') { return convertSuperClassHelper(