Enable astro/tsconfigs/strictest in the preview package (#2834)

This commit is contained in:
Paweł Kuna
2026-08-08 00:51:32 +02:00
committed by GitHub
parent 512ede545c
commit 16e1403bc8
22 changed files with 102 additions and 61 deletions
+12
View File
@@ -0,0 +1,12 @@
import { describe, expect, it } from 'vitest'
import { requireIndex } from './array'
describe('requireIndex', () => {
it('returns the entry at the given index', () => {
expect(requireIndex(['a', 'b', 'c'], 1)).toBe('b')
})
it('throws when the index is out of bounds', () => {
expect(() => requireIndex(['a'], 5)).toThrow('Expected an entry at index 5')
})
})
+11
View File
@@ -0,0 +1,11 @@
// Indexes into demo-data arrays (people.json, photos.json, …) that pages trust to have
// an entry at a given position. Throws instead of silently rendering `undefined` if that
// assumption is ever violated (e.g. a seed file shrinks).
export function requireIndex<T>(array: readonly T[], index: number): T {
const item = array[index]
if (item === undefined) {
throw new Error(`Expected an entry at index ${index}, got undefined (array has ${array.length} entries)`)
}
return item
}