Skip to content

Unable to assign a dynamic schema type #29

@luukvhoudt

Description

@luukvhoudt

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions