Skip to content

@vercel/analytics/astro: published dist/astro/component.ts fails type-checking with TS2578 (unused @ts-expect-error) #222

Backlog

Description

@nemofq

Description

@vercel/analytics/astro resolves to a TypeScript source file, dist/astro/component.ts, which is published with a @ts-expect-error directive that only applies inside this repository:

export type {
  AnalyticsProps,
  BeforeSend,
  BeforeSendEvent,
  // @ts-expect-error this filed is copied to dist, so it's ok to reference the generated index.d.ts
} from '../index.d.ts';
export { default } from './index.astro';

In packages/web/src/astro/, ../index.d.ts doesn't exist, so the directive is needed. In the published package, dist/index.d.ts does exist, so the import resolves, the directive is unused, and TypeScript reports:

node_modules/@vercel/analytics/dist/astro/component.ts(5,3): error TS2578: Unused '@ts-expect-error' directive.

Because the file is .ts and not .d.ts, skipLibCheck doesn't suppress it. astro check doesn't surface it, but any tsc run that follows the import does. That now includes Astro projects type-checked with TypeScript 7.1 and @astrojs/ts-content-mapper, where this is the only error in an otherwise clean project.

Reproduction

  1. In an Astro project, add import Analytics from '@vercel/analytics/astro'; to a layout.
  2. Install typescript@7.1.0-beta and @astrojs/ts-content-mapper@0.2.0, and add to tsconfig.json:
    "contentMappers": [
      { "package": "@astrojs/ts-content-mapper", "extensions": [".astro"] }
    ]
  3. Run astro sync && tsc --noEmit --runExternalCode.

Result: the TS2578 error above, exit code 2.

It also reproduces without the mapper: import @vercel/analytics/astro from any .ts file and run tsc --noEmit with TypeScript 6.0.3.

Versions

  • @vercel/analytics 2.0.1 (latest) and 2.1.0-canary.5 (beta); main still has the directive in packages/web/src/astro/component.ts
  • TypeScript 7.1.0-beta with @astrojs/ts-content-mapper 0.2.0, and TypeScript 6.0.3
  • Astro 7.4.13, Node 24

Suggested fix

Any of these:

  • Replace // @ts-expect-error with // @ts-ignore in component.ts. @ts-ignore is valid both in the source tree and in dist. Making that one change in the installed 2.0.1 file makes tsc pass.
  • Strip or rewrite the directive when the file is copied to dist.
  • Publish a declaration file for the ./astro export instead of pointing it at a .ts source file.

Related

#169 and #219 are about the ./astro export's missing types condition. #219 points types at the same component.ts, so it doesn't change this error.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions