chore: Extends i18n types to avoid any#2121
chore: Extends i18n types to avoid any#2121PatrykKuniczak wants to merge 9 commits intowxt-dev:mainfrom
any#2121Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@wxt-dev/analytics
@wxt-dev/auto-icons
@wxt-dev/browser
@wxt-dev/i18n
@wxt-dev/is-background
@wxt-dev/module-react
@wxt-dev/module-solid
@wxt-dev/module-svelte
@wxt-dev/module-vue
@wxt-dev/runner
@wxt-dev/storage
@wxt-dev/unocss
@wxt-dev/webextension-polyfill
wxt
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2121 +/- ##
==========================================
- Coverage 76.39% 76.19% -0.20%
==========================================
Files 115 115
Lines 3092 3092
Branches 684 684
==========================================
- Hits 2362 2356 -6
- Misses 649 653 +4
- Partials 81 83 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
aklinker1
left a comment
There was a problem hiding this comment.
I only looked a the test file. Revert those changes so the tests expect type errors for invalid function calls, then I'll look at the rest of this PR.
There was a problem hiding this comment.
This file tests types by expecting type errors for invalid function calls. That means we need the // @ts-expect-error is present here. Revert it or find another way to test that type errors exist in these cases.
aklinker1
left a comment
There was a problem hiding this comment.
Woops, meant to request changes.
|
@aklinker1 Now it should be good |
18b6aee to
d7363bb
Compare
d7363bb to
d0e41a7
Compare
|
@aklinker1 Conflicts resolved 😄 |
11dfd0e to
e254767
Compare
|
@aklinker1 Again, let's check it :) |
|
@PatrykKuniczak What does this PR do? Why do your changes make the type-setup better? I'm not seeing anything immediately stand out after reviewing the changes. You made some good changes to make the internal code more type-safe, but I can't tell what your changes to the public APIs/types are doing |
What do you mean? |
There was a problem hiding this comment.
I pulled out all the changes to this file to #2201, they look good to me with a few tweaks.
| export function createI18n< | ||
| T extends I18nStructure = DefaultI18nStructure, | ||
| >(): I18n<T> { | ||
| const t = (key: string, ...args: any[]) => { | ||
| export function createI18n<T extends I18nStructure>(): I18n<T> { |
There was a problem hiding this comment.
OK, so we removed the default value from here... I'm not sure I like that. It is a breaking change for non-WXT projects. What do those projects use for the type param now?
There was a problem hiding this comment.
If they doesn't provide any type, I18nStructure will take default value:
export type I18nStructure = {
[K: string]: {
plural: boolean;
substitutions: 0 ... 9;
};I'm right?
| }; | ||
|
|
||
| export interface I18n<T extends I18nStructure> { | ||
| t: string extends keyof T ? DefaultTFunction<keyof T & string> : TFunction<T>; |
There was a problem hiding this comment.
OK, so we're splitting up the typing... We're using the new DefaultTFunction type when.... T extends never? Is that what T defaults to when not provided in createI18n?
There was a problem hiding this comment.
I18nStructure is defined as { [K: string]: I18nFeatures } - a signature with string keys
When T = I18nStructure, keyof T evaluates to string = true
So the condition string extends keyof T evaluates to string extends string
Therefore it uses DefaultTFunction (the "no type-safety" version)
What does this PR do? You haven't stated anywhere what the purpose of these changes are and it's hard for me to guess by just looking at the changes. Is the purpose just to remove If so, your PR title and description don't mention that at all. |
Ooo yeah, i've wanted to avoid |
This reverts commit 61bd550.
e254767 to
a548c55
Compare
|
@aklinker1 I hope now, it's more readable 😄 |
any
Overview
I've done my best, to type it, if anybody have better idea to do this, i'm open for edit suggestion.
Manual Testing
Let's see if CI pass