Giter VIP home page Giter VIP logo

Comments (5)

Conaclos avatar Conaclos commented on June 18, 2024 1

I can't find any TS docs about it, but it is valid - see some examples from the TS codebase itself https://github.com/search?q=repo%3Amicrosoft%2FTypeScript+declare+const&type=code

declare const is indeed valid and documented. What I am talking about is making cohabit an import and a declare const with the same name.

I took some time to test locally, and if the imported file exists, I get an error:

// @filename a.jts
export {}


// @filename b.js
import * as ns from "./a.js";
//          ^^
//          Import declaration conflicts with local declaration of 'ns'. ts(2440)

declare const ns: {
  f: () => unknown
};

However, if the imported file doesn't exist (your case?), TypeScript doesn't report the error – this is likely a bug from TSC.
Thus, I think it is an error of using an identical name for an import and a declare const.

from biome.

AbhiPrasad avatar AbhiPrasad commented on June 18, 2024 1

Got it, thanks for helping investigate, I'll also open a bug with TS about the compiler issue.

from biome.

Conaclos avatar Conaclos commented on June 18, 2024

I was not aware of this kind of declaration merging. Do you have any TypeScript resources that document this? This looks wrong to me 🤔

I could suggest using module augmentation instead:

import * as routeModule from "__SENTRY_WRAPPING_TARGET_FILE__";

declare module "__SENTRY_WRAPPING_TARGET_FILE__" {
  export function GET(...args: unknown[]): unknown;
  /* ... */
}

export const GET = [routeModule.GET, 'GET'];

I think it is more idiomatic in TypeScript.

from biome.

AbhiPrasad avatar AbhiPrasad commented on June 18, 2024

I can't find any TS docs about it, but it is valid - see some examples from the TS codebase itself https://github.com/search?q=repo%3Amicrosoft%2FTypeScript+declare+const&type=code

I agree your change feels more idomatic, but I think biome should still account for this edge case.

from biome.

ematipico avatar ematipico commented on June 18, 2024

I agree your change feels more idomatic, but I think biome should still account for this edge case.

While I feel the sentiment, I find it very hard to explain something that we can't document. When we create a rule, we always strive to write something that we can properly document, with references too.

If we can't document this edge case, how can we prove that what we are doing is the right way?

from biome.

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.