You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@vercel/analytics/astro: published dist/astro/component.ts fails type-checking with TS2578 (unused @ts-expect-error) #222
@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:
exporttype{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:
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
In an Astro project, add import Analytics from '@vercel/analytics/astro'; to a layout.
Install typescript@7.1.0-beta and @astrojs/ts-content-mapper@0.2.0, and add to tsconfig.json:
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