Non-English locales lose Infinity/-Infinity in "invalid type" messages
Summary
en.ts special-cases non-finite numbers when formatting the received type, so Infinity and -Infinity appear literally in the message. No other locale does this — all of them fall back to the generic "number", losing information the English message keeps.
Reproduction
import * as z from 'zod'
import { ko, ja, de } from 'zod/locales'
for (const [name, locale] of [['en', z.locales.en], ['ko', ko], ['ja', ja], ['de', de]]) {
z.config(locale())
console.log(name, z.string().safeParse(Infinity).error.issues[0].message)
}zod 4.6.5:
en Invalid input: expected string, received Infinity
ko 잘못된 입력: 예상 타입은 string, 받은 타입은 number입니다
ja 無効な入力: stringが期待されましたが、数値が入力されました
de Ungültige Eingabe: erwartet string, erhalten Zahl-Infinity behaves the same way. NaN is unaffected, because every locale carries nan: "NaN" in its TypeDictionary — only the non-finite handling is English-only.
Cause
en.ts routes the received type through a helper:
function getTypeName(type: errors.$ZodInvalidTypeExpected, input?: unknown): string {
if (type === 'number' && typeof input === 'number' && !Number.isFinite(input)) {
return String(input)
}
return TypeDictionary[type] ?? type
}Other locales resolve it inline instead:
const received = TypeDictionary[receivedType] ?? receivedTypeGrepping getTypeName across packages/zod/src/v4/locales/ matches en.ts only.
Question before opening a PR
Is this intended as an English-only refinement, or should the non-finite handling be shared across locales? If it should be shared, my read is that lifting it into a shared helper is preferable to copying the branch into every locale file. Happy to open the PR either way — just want to confirm the direction first.
Source: colinhacks/zod