Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defineCollection and other declarations missing from generated types for "astro:content" module #12439

Open
1 task
bsidhom opened this issue Nov 15, 2024 · 2 comments
Labels
needs triage Issue needs to be triaged

Comments

@bsidhom
Copy link

bsidhom commented Nov 15, 2024

Astro Info

Astro                    v4.16.12
Node                     v23.2.0
System                   macOS (arm64)
Package Manager          yarn
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No browser; this is a development issue

Describe the Bug

With a minimal project using yarn 4.5.1, Astro 4.16.12 and the latest official VSCode Astro extension, I'm getting an error in my src/content/config.ts file when I try to do the following import:

import { defineCollection, z } from "astro:content";

This is the error I see:

Module '"astro:content"' has no exported member 'defineCollection'.ts(2305)

I can confirm that, indeed, the defineCollection and z declarations are missing from the .astro/astro/content.d.ts typing file. (I can share the contents of that file if desired, but you should be able to reproduce with my sample.)

I've linked a minimal reproduction. To initialize the project, I just ran yarn init -2, added the relevant Astro dev dependencies, and pasted in a few filler content files. I see the same issue whether I put everything into dependencies or devDependencies in my package.json, so it does not appear to be a dev-vs-runtime dependency issue.

Note that I wasn't able to insert slashes (/) into the gist files, so I've replaced those with underscores (_).

I've also run astro sync, astro check, and astro build. All result in the same VSCode type error. I am able to successfully build and view the website.

Finally, the closest previous issue I could find to this one was #5711, which seems to be complaining that the module doesn't exist at all. This is not what I'm seeing; instead, I'm seeing that not all of the module exports are getting into the declaration file.

What's the expected result?

The .astro/astro/content.d.ts should contain all relevant typings and should allow type checking of collection schemas.

Link to Minimal Reproducible Example

https://gist.github.com/bsidhom/88417490e8dc651a17f1608c5af3067c

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Nov 15, 2024
@Mikescops
Copy link

Mikescops commented Nov 15, 2024

I do have the same issue.

Astro                    v4.16.12
Node                     v22.11.0
System                   Linux (arm64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/react
                         @astrojs/mdx

Worth to mention that the build works perfectly, it's just in Vscode.

Also here is what eslint says:

> eslint .


/workspaces/website/.astro/astro/content.d.ts
    4:46  error  The `{}` ("empty object") type allows any non-nullish value, including literals like `0` and `""`.
- If that's what you want, disable this lint rule with an inline comment or configure the 'allowObjectTypes' rule option.
- If you want a type meaning "any object", you probably want `object` instead.
- If you want a type meaning "any value", you probably want `unknown` instead  @typescript-eslint/no-empty-object-type
    6:44  error  Unexpected any. Specify a different type                                                                                                                                                                                                                                                                                                                                                   @typescript-eslint/no-explicit-any
    7:44  error  The `{}` ("empty object") type allows any non-nullish value, including literals like `0` and `""`.
- If that's what you want, disable this lint rule with an inline comment or configure the 'allowObjectTypes' rule option.
- If you want a type meaning "any object", you probably want `object` instead.
- If you want a type meaning "any value", you probably want `unknown` instead  @typescript-eslint/no-empty-object-type
   16:43  error  Unexpected any. Specify a different type                                                                                                                                                                                                                                                                                                                                                   @typescript-eslint/no-explicit-any
   40:34  error  Unexpected any. Specify a different type                                                                                                                                                                                                                                                                                                                                                   @typescript-eslint/no-explicit-any
  148:53  error  Unexpected any. Specify a different type                                                                                                                                                                                                                                                                                                                                                   @typescript-eslint/no-explicit-any

/workspaces/website/.astro/types.d.ts
  2:1  error  Do not use a triple slash reference for astro/content.d.ts, use `import` style instead  @typescript-eslint/triple-slash-reference

✖ 7 problems (7 errors, 0 warnings)

@Mikescops
Copy link

Ah anyway, I figured out I forgot to include "include": ["./src/**/*.astro"] in my tsconfig.json. Now it works like a charm, sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants