swc-project/swc · error

illegal conversion: Cannot convert {:?} to TSLiteralTypeLite

Error message

illegal conversion: Cannot convert {:?} to TSLiteralTypeLiteral

What it means

A defensive catch-all arm in the babelify conversion for TsLit to TSLiteralTypeLiteral (typescript.rs:812). It fires when the TsLit enum carries a literal variant with no mapped ESTree TSLiteralTypeLiteral kind (anything beyond Number/Str/Bool/BigInt, such as a future or extension variant). In practice it signals that the TsLit input is not one of the four supported literal kinds and the conversion table is incomplete for that variant.

Source

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

    fn babelify(self, ctx: &Context) -> Self::Output {
        TSLiteralType {
            base: ctx.base(self.span),
            literal: self.lit.babelify(ctx),
        }
    }
}

impl Babelify for TsLit {
    type Output = TSLiteralTypeLiteral;

    fn babelify(self, ctx: &Context) -> Self::Output {
        match self {
            TsLit::Number(n) => TSLiteralTypeLiteral::Numeric(n.babelify(ctx)),
            TsLit::Str(s) => TSLiteralTypeLiteral::String(s.babelify(ctx)),
            TsLit::Bool(b) => TSLiteralTypeLiteral::Boolean(b.babelify(ctx)),
            TsLit::BigInt(i) => TSLiteralTypeLiteral::BigInt(i.babelify(ctx)),
            _ => panic!(
                "illegal conversion: Cannot convert {:?} to TSLiteralTypeLiteral",
                &self
            ),
        }
    }
}

// TODO(dwoznicki): Babel does not appear to have a corresponding template
// literal TS node.
impl Babelify for TsTplLitType {
    type Output = String;

    fn babelify(self, _ctx: &Context) -> Self::Output {
        panic!("unimplemented");
    }
}

impl Babelify for TsInterfaceDecl {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Determine which TsLit variant hit the catch-all (log it) and add a matching arm to TSLiteralTypeLiteral
  2. Reject the input earlier with a descriptive conversion error if the literal kind is genuinely unsupported in ESTree
  3. Guard at the API boundary: only pass TsLit values whose kind is known-supported
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/swc_estree_compat/src/babelify/typescript.rs:812 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/1340b88261833172. Report an issue: GitHub.