withastro / language-tools

Language tools for Astro
MIT License
267 stars 52 forks source link

🐛 BUG: Astro check support for Object.groupBy() #877

Closed MerlinMason closed 4 months ago

MerlinMason commented 4 months ago

Describe the Bug

Node v21.0.0 adds support for Object.groupBy() method - this in turn is supported by TypeScript v5.4.0 release.

This runs fine in Astro however it fails astro check.

From what I can tell, this is due to https://github.com/withastro/language-tools/blob/main/pnpm-lock.yaml#L34 using TypeScript v5.2.2

Steps to Reproduce

  1. npm init astro with Node >= 21
  2. Add the following to the top of an Astro page
    const rockets = [
    { name: "Orion", manufacturer: "NASA" },
    { name: "Falcon Heavy", manufacturer: "SpaceX" },
    ] as const;
    const groupedByManufacturer = Object.groupBy(
    rockets,
    ({ manufacturer }) => manufacturer,
    );
    console.log("NASA Rocket: ", groupedByManufacturer.NASA?.[0].name);
  3. Console output should be NASA Rocket: Orion
  4. Run astro check
  5. Error Property 'groupBy' does not exist on type 'ObjectConstructor'.
MerlinMason commented 4 months ago

I've tried to create a PR to address this but don't seem to have permission to push a new branch :(

Fryuni commented 4 months ago

You need to fork the repo and push the branch to your fork before opening a PR. https://docs.github.com/en/get-started/exploring-projects-on-github/contributing-to-a-project

But the typescript dependency is a peer dependency with range ^5.0.0, it will use whichever version of typescript is used in your own project.

If you run npm install -P typescript@latest, you'll get the latest version in your Astro project, and it should work. Can you try that?

MerlinMason commented 4 months ago

ohhh I see - sorry! Thanks, have tried that and it works :)

Princesseuh commented 4 months ago

FYI, we don't hardcode any versions of TypeScript inside the tooling, we always use whatever the project has. So for missing properties like this, you can always just update your version of TypeScript.