Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to assign a dynamic schema type #3

Open
5 tasks done
luukvhoudt opened this issue Nov 17, 2023 · 1 comment
Open
5 tasks done

Unable to assign a dynamic schema type #3

luukvhoudt opened this issue Nov 17, 2023 · 1 comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed status: review needed Request for review

Comments

@luukvhoudt
Copy link

luukvhoudt commented Nov 17, 2023

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.
@luukvhoudt luukvhoudt added the status: review needed Request for review label Nov 17, 2023
@kazupon
Copy link
Member

kazupon commented Dec 13, 2023

welcome contribution :)

@kazupon kazupon added good first issue Good for newcomers help wanted Extra attention is needed labels Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed status: review needed Request for review
Projects
None yet
Development

No branches or pull requests

2 participants