Skip to content

Code#lang types not exported #14009

@rgant

Description

@rgant

Astro Info

Astro                    v5.10.1
Node                     v24.2.0
System                   macOS (arm64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             @vite-pwa/astro-integration
                         @playform/compress
                         @kindspells/astro-shield
                         @astrojs/sitemap

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

No response

Describe the Bug

---
const fetchedCode = await fetchCode();
const code: string = fetchedCode.content;
const language: string = fetchedCode.language; // `fetchedCode` is something like { content: string; language: string }
---
<Code code={code} lang={language} />
                  ^^^^ Type 'string' is not assignable to type 'BundledLanguage | SpecialLanguage | LanguageRegistration'.ts(2322)

I'm writing a Component to embed GitHub code from my repo/gists into my website. Because of the strict nature of my code base I need to be able to specify a more strict type for language than just a string. Astro doesn't expose the BundledLanguage | SpecialLanguage | LanguageRegistration to me anywhere that I can see. And since [email protected] is a dependency of astro, not my project I don't have safe access to those types.

What's the expected result?

I expect that Astro would either not require a narrow type for the lang attribute, or would expose that type so that end-users can access it directly.

I will admit that this is a problem of my own making. I want to be super strict with my types, but I also don't want have to write or install (much) code just to make the linters and tsc happy.

If you provide me with some indication of how you think best to resolve this issue I am happy to submit a PR to Astro. For now I'm just disabling the complaint with a comment.

Link to Minimal Reproducible Example

https://github.com/rgant/rob.gant.ninja/blob/2cb3e593b9cc751c778c3c39198bf98f1227d7e9/src/components/github-embed.astro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

- P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)help wantedPlease help with this issue!

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions