Skip to content

fix(types): make applyGetPermalinks TypeScript 6 strict-safe - #708

Merged
prototypa merged 1 commit into
arthelokyo:mainfrom
danfitz36:fix/applygetpermalinks-ts6-implicit-any
Jun 4, 2026
Merged

fix(types): make applyGetPermalinks TypeScript 6 strict-safe#708
prototypa merged 1 commit into
arthelokyo:mainfrom
danfitz36:fix/applygetpermalinks-ts6-implicit-any

Conversation

@danfitz36

Copy link
Copy Markdown
Contributor

What

Makes applyGetPermalinks (src/utils/permalinks.ts) compile cleanly under TypeScript 6.0, where strict / noImplicitAny is on by default.

Fixes #707.

Why

The function took menu: object = {}, iterated with for...in, and read/wrote via bracket indexing (menu[key], obj[key]) with no return-type annotation. With noImplicitAny enabled, that produced 19 errors (17× ts7053, 1× ts7023, 1× ts7024) — indexing a bare object/{} and an un-annotated recursive return type.

Change

  • menu: unknown with an explicit : unknown return type (breaks the recursive implicit-any inference)
  • Object.entries(menu) instead of for...in + bracket indexing (no indexing of a non-indexable type)
  • Record<string, unknown> accumulator instead of const obj = {}
  • A small MenuHref type to narrow the href object branch

Runtime behavior is unchanged — it's a pure typing fix.

Verification

With typescript@6 installed, npx astro check no longer reports any errors in permalinks.ts (was 19, now 0). eslint and prettier pass on the changed file.

Note (out of scope)

While verifying, astro check under TS 6 also surfaced the same {}-indexing pattern in src/utils/blog.ts (4× ts7053) and an unrelated ts(2882) for a @fontsource-variable/* side-effect import in CustomStyles.astro. Those are left out of this PR to keep it focused on #707, but they're part of the same TS 6 readiness effort — happy to follow up with a PR for blog.ts if you'd like.

Under TypeScript 6.0, strict (and noImplicitAny) is on by default, which
surfaced 19 implicit-any errors in applyGetPermalinks (ts7053/7023/7024):
indexing a bare object/{} and an un-annotated recursive return type.

Type menu as unknown with an explicit return type, iterate with
Object.entries instead of for...in bracket indexing, and use a
Record<string, unknown> accumulator. Behavior is unchanged.

Fixes arthelokyo#707
@prototypa
prototypa merged commit 9167087 into arthelokyo:main Jun 4, 2026
2 checks passed
@prototypa

Copy link
Copy Markdown
Contributor

Thanks @danfitz36

prototypa pushed a commit that referenced this pull request Jun 4, 2026
Same TS 6 strict-by-default issue as #708, in src/utils/blog.ts:
getStaticPathsBlogCategory and getStaticPathsBlogTag build untyped {}
accumulators and index them by string, producing 4 implicit-any
errors (ts7053) under noImplicitAny.

Type both accumulators as Record<string, Taxonomy> (the existing type
for Post.category / Post.tags[]) and drop the now-redundant optional
chaining on the narrowed index keys. Behavior is unchanged.

Related to #707.
prototypa added a commit that referenced this pull request Aug 4, 2026
…licit-any

fix(types): make applyGetPermalinks TypeScript 6 strict-safe
prototypa pushed a commit that referenced this pull request Aug 4, 2026
Same TS 6 strict-by-default issue as #708, in src/utils/blog.ts:
getStaticPathsBlogCategory and getStaticPathsBlogTag build untyped {}
accumulators and index them by string, producing 4 implicit-any
errors (ts7053) under noImplicitAny.

Type both accumulators as Record<string, Taxonomy> (the existing type
for Post.category / Post.tags[]) and drop the now-redundant optional
chaining on the narrowed index keys. Behavior is unchanged.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

applyGetPermalinks breaks under TypeScript 6.0 strict-by-default (19 implicit-any errors in permalinks.ts)

2 participants