{"record":{"id":"58e8fdce493d6534","repo":"swc-project/swc","slug":"flow-type-cast","errorCode":null,"errorMessage":"flow type cast","messagePattern":"flow type cast","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_estree_compat/src/swcify/expr.rs","lineNumber":842,"sourceCode":"        OptChainExpr {\n            span: ctx.span(&self.base),\n            optional: self.optional,\n            base: Box::new(OptChainBase::Call(OptCall {\n                span: ctx.span(&self.base),\n                callee: self.callee.swcify(ctx),\n                args: self.arguments.swcify(ctx).into_iter().flatten().collect(),\n                type_args: self.type_parameters.swcify(ctx).map(From::from),\n                ..Default::default()\n            })),\n        }\n    }\n}\n\nimpl Swcify for TypeCastExpression {\n    type Output = Never;\n\n    fn swcify(self, _: &Context) -> Self::Output {\n        unimplemented!(\"flow type cast\")\n    }\n}\n\nimpl Swcify for swc_estree_ast::JSXElement {\n    type Output = swc_ecma_ast::JSXElement;\n\n    fn swcify(self, ctx: &Context) -> Self::Output {\n        swc_ecma_ast::JSXElement {\n            span: ctx.span(&self.base),\n            opening: self.opening_element.swcify(ctx),\n            children: self.children.swcify(ctx),\n            closing: self.closing_element.swcify(ctx),\n        }\n    }\n}\n\nimpl Swcify for swc_estree_ast::JSXOpeningElement {\n    type Output = swc_ecma_ast::JSXOpeningElement;","sourceCodeStart":824,"sourceCodeEnd":860,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_estree_compat/src/swcify/expr.rs#L824-L860","documentation":"The estree TypeCastExpression is Flow's `(value as T)`-style cast (Babel Flow output). SWC's AST has no Flow cast expression (only TsAsExpr for TS), so Swcify for TypeCastExpression is declared with Output = Never and immediately panics with `unimplemented!(\"flow type cast\")`.","triggerScenarios":"Running swcify on a Babel AST produced by a Flow-mode parse that contains Flow type cast expressions, e.g. `(x: MyType)` or `(x >>> null)`-style Flow annotations.","commonSituations":"Converting Flow codebases (legacy React Native, old Facebook packages) through Babel into SWC-based tooling without first stripping Flow types.","solutions":["Run Flow type stripping (@babel/plugin-transform-flow-strip-types) on the AST/source before swcify","Parse the code as TypeScript when the casts are actually TS `as` casts","Drop or replace TypeCastExpression nodes with their inner expression in a pre-conversion pass"],"exampleFix":"// before\nconst n = (x: number); // Flow cast -> TypeCastExpression -> panic\n\n// after\nconst n = x; // after flow-strip-types, or parse as TS: x as number","handlingStrategy":"validation","validationCode":"// Node: strip Flow types before swcify\nconst stripped = require('@babel/core').transformSync(code, {\n  plugins: ['@babel/plugin-transform-flow-strip-types'],\n  code: true,\n}).code;","typeGuard":"function isFlowTypeCast(node) {\n  return node.type === 'TypeCastExpression';\n}","tryCatchPattern":null,"preventionTips":["Treat TypeCastExpression nodes as poison for swcify — strip or unwrap them first","Parse new sources with the TypeScript syntax when possible","Keep a Flow-fixture test in pipelines that accept community-supplied code"],"tags":["swc","babel","flow","type-cast","ast-conversion"],"backgroundTag":"unimplemented-ast-node-conversion","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}