Giter Club home page Giter Club logo

Comments (4)

alangpierce avatar alangpierce commented on September 21, 2024 1

Hi @renhiyama, unfortunately your suggestion of export const <var> = 0; is out of scope for Sucrase. Sucrase tries to match the behavior of TypeScript transpileModule as closely as possible (with minor exceptions), since it's meant to be a faster drop-in replacement. Babel, swc, and esbuild take the same approach, so this issue you're raising is a general issue (which already has some solutions, see below), not specific to Sucrase. See this playground link for how the output compares. If Sucrase did produce a runtime-visible export, it cause bugs for code iterating through a * import, or might conflict with an explicit value export.

The typical way to avoid the error you're seeing is to ensure that the code is removed on the import side. There are two historical ways this has been done:

  • Automatic import elision. The default behavior for both TypeScript and Sucrase is to detect that GlobOptions is only used as a type, and to remove that import line (or just the one named import) in the resulting JS. The isolatedModules TypeScript option can help flag some issues like re-exports that can cause issues here.
  • Explicit type syntax in the import. With Sucrase keepUnusedImports and TypeScript verbatimModuleSyntax (and its deprecated alternatives), the way to remove type imports is to explicitly write type GlobOptions.

Happy to reconsider if I'm overlooking a case where TypeScript (or another tool) emits a const declaration like you're talking about, but generally Sucrase follows TypeScript's lead on how file-by-file transpilation should work.

from sucrase.

easrng avatar easrng commented on September 21, 2024

Can't you just import types explicitly as types import { type GlobOptions } from "..."?

from sucrase.

renhiyama avatar renhiyama commented on September 21, 2024

Can't you just import types explicitly as types import { type GlobOptions } from "..."?

that's not what this issue is about. Sucrase seems to break any code that exports interfaces when converting any typescript code to javascript. In order to not break any compability issues, my suggestion posted above is the only solution.

Your suggestion doesn't make sense because sucrase's point is to make stuff work, without needing much changes, nor break anything up.

from sucrase.

renhiyama avatar renhiyama commented on September 21, 2024

@alangpierce could you please look at this issue asap?

from sucrase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.