intlify / intlify/srvmid

Unable to assign a dynamic schema type

Open
#29 1 comment 0 reactions 0 assignees View on GitHub
good first issue help wanted Hono status: review needed
Dominant language
TypeScript
Stars
13
Forks
2
Avg merge
4h 14m
Merged PRs (30d)
4

Description

### Describe the bug

Consider the following factory

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

export function createI18nMiddleware>(
schema: TSchema,
translations: Record = {},
) {
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 ? TSchema : LocaleMessage'.
Type 'Record' is not assignable to type 'TSchema extends LocaleMessage ? TSchema : LocaleMessage'
```

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

### Reproduction

-

### System Info

```Shell
-
```

### 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](https://github.com/intlify/.github/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guide](https://github.com/intlify/hono/blob/main/CONTRIBUTING.md).
- [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](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.