swc-project/swc · error

illegal conversion: Cannot convert {:?} to Identifier

Error message

illegal conversion: Cannot convert {:?} to Identifier

What it means

Raised by `From<TsFnParamOutput> for Identifier`, which unwraps the single Id variant into a bare Identifier. The panic fires whenever the converted function parameter is a Rest, Array, or Object variant, because only a plain identifier parameter can be represented as an Identifier. It indicates upstream code assumed a parameter was a simple binding when it was actually a rest or destructuring pattern.

Source

Thrown at crates/swc_estree_compat/src/babelify/typescript.rs:108

        }
    }
}

impl From<TsFnParamOutput> for IdOrRest {
    fn from(o: TsFnParamOutput) -> Self {
        match o {
            TsFnParamOutput::Id(i) => IdOrRest::Id(i),
            TsFnParamOutput::Rest(r) => IdOrRest::Rest(r),
            _ => panic!("illegal conversion: Cannot convert {:?} to IdOrRest", &o),
        }
    }
}

impl From<TsFnParamOutput> for Identifier {
    fn from(o: TsFnParamOutput) -> Self {
        match o {
            TsFnParamOutput::Id(i) => i,
            _ => panic!("illegal conversion: Cannot convert {:?} to Identifier", &o),
        }
    }
}

impl Babelify for TsTypeParamDecl {
    type Output = TSTypeParameterDeclaration;

    fn babelify(self, ctx: &Context) -> Self::Output {
        TSTypeParameterDeclaration {
            base: ctx.base(self.span),
            params: self.params.babelify(ctx),
        }
    }
}

impl Babelify for TsTypeParam {
    type Output = TSTypeParameter;

View on GitHub (pinned to 5176682b65)

Solutions

  1. Match on TsFnParamOutput::Id explicitly at the call site instead of blindly using .into(), and handle the other variants
  2. Validate that the original TsFnParam is TsFnParam::Ident before performing the conversion
  3. If rest parameters can legitimately appear, use the IdOrRest conversion instead which accepts one more variant
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/swc_estree_compat/src/babelify/typescript.rs:108 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/fe66bf4581a1977f. Report an issue: GitHub.