hono icon indicating copy to clipboard operation
hono copied to clipboard

Unable to assign a dynamic schema type

Open luukvhoudt opened this issue 2 years ago • 1 comments

Describe the bug

Consider the following factory

import {
	defineI18nMiddleware,
	detectLocaleFromAcceptLanguageHeader
} from '@intlify/hono';

export function createI18nMiddleware<TSchema extends Record<string, string>>(
	schema: TSchema,
	translations: Record<string, TSchema> = {},
) {
	return defineI18nMiddleware<{ message: TSchema }>({
		locale: detectLocaleFromAcceptLanguageHeader,
		messages: { ...translations, en: schema },
		                                               // ^^ <-- TS error
	});
}

The TS error

Type 'TSchema' is not assignable to type 'TSchema extends LocaleMessage<string> ? TSchema : LocaleMessage<string>'.
  Type 'Record<string, string>' is not assignable to type 'TSchema extends LocaleMessage<string> ? TSchema : LocaleMessage<string>'

Not sure if it's me doing something wrong here.

Reproduction

System Info

-

Used Package Manager

other (if you use other package manager, please describe at the Additional context)

Additional context

bun v1.0.12

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the Contributing Guide.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [X] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • [X] The provided reproduction is a minimal reproducible of the bug.

luukvhoudt avatar Nov 17 '23 00:11 luukvhoudt

welcome contribution :)

kazupon avatar Dec 13 '23 03:12 kazupon