Skip to content

astro-check (error / warning): Tighten lib/tips.ts types end-to-end #577

@lsr-explore

Description

@lsr-explore

Tighten lib/tips.ts types end-to-end

Labels: types, tech-debt
Estimated PR size: ~3 files

Note

Ticket description was generated using Claude Code. Review before starting on a fix.

Note

The following issue adds support for npm run astro:check

Summary

Same pattern as issue title = Tighten lib/blog.ts types end-to-end, but for lib/tips.ts. Multiple functions accept tips? / tip parameters with implicit any, leading to a downstream unknown[] vs string[] mismatch in getTipCatalog.

astro check errors & warnings

src/lib/tips.ts:59:5 - error ts(2322): Type 'unknown[]' is not assignable to type 'string[]'.
  Type 'unknown' is not assignable to type 'string'.

59     categories,
       ~~~~~~~~~~
src/lib/tips.ts:52:37 - warning ts(7044): Parameter 'tips' implicitly has an 'any' type, but a better type may be inferred from usage.

52 export async function getTipCatalog(tips?): Promise<TipCatalog> {
                                       ~~~~~
src/lib/tips.ts:41:37 - warning ts(7044): Parameter 'tips' implicitly has an 'any' type, but a better type may be inferred from usage.

41 export async function getMostRecent(tips?): Promise<CollectionEntry<"atotw">> {
                                       ~~~~~
src/lib/tips.ts:29:37 - warning ts(7044): Parameter 'tips' implicitly has an 'any' type, but a better type may be inferred from usage.

29 export async function orderByRecent(tips?) {
                                       ~~~~~
src/lib/tips.ts:21:38 - warning ts(7044): Parameter 'tip' implicitly has an 'any' type, but a better type may be inferred from usage.

21 export async function getRelatedTips(tip) {
                                        ~~~
src/lib/tips.ts:15:26 - warning ts(7044): Parameter 'blog' implicitly has an 'any' type, but a better type may be inferred from usage.

15     ...new Set(tips.map((blog) => blog.data.tags).flat()),
                            ~~~~
src/lib/tips.ts:11:40 - warning ts(7044): Parameter 'tips' implicitly has an 'any' type, but a better type may be inferred from usage.

11 export async function getTipCategories(tips?) {
                                          ~~~~~

Plus warnings in src/pages/tips/index.astro:

src/pages/tips/index.astro:18:7  - warning ts(6198): All destructured elements are unused.
src/pages/tips/index.astro:15:1  - warning ts(6133): 'startCase' is declared but its value is never read.

Suggested fix

In src/lib/tips.ts:

  1. Type each tips? parameter as CollectionEntry<"atotw">[] | undefined.
  2. Type tip parameter in getRelatedTips as CollectionEntry<"atotw">.
  3. Default tips ??= await getCollection("atotw") inside the function.
  4. Fix the categories return type so Promise<TipCatalog> is honest — [...new Set(tips.map(t => t.data.tags).flat())] should be string[] once tips is typed.

In src/pages/tips/index.astro:

  • The unused startCase import suggests the page once rendered category names with title-case. Either re-introduce that rendering or remove the unused destructuring of categories. Decide based on intended UX.

Affected files

  • src/lib/tips.ts
  • src/pages/tips/index.astro
  • (possibly) src/layouts/TipLayout.astro if its imports start type-checking better as a side-effect

Acceptance criteria

  • All errors and ts(7044) warnings in lib/tips.ts clear.
  • tips/index.astro warnings clear (either by using the unused destructured values or removing them).
  • No new any casts.
  • Tips index and individual tip pages still render correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions