Skip to content

chore: Extends i18n types to avoid any#2121

Open
PatrykKuniczak wants to merge 9 commits intowxt-dev:mainfrom
PatrykKuniczak:chore/add-new-types-for-i18n
Open

chore: Extends i18n types to avoid any#2121
PatrykKuniczak wants to merge 9 commits intowxt-dev:mainfrom
PatrykKuniczak:chore/add-new-types-for-i18n

Conversation

@PatrykKuniczak
Copy link
Collaborator

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

@netlify
Copy link

netlify bot commented Feb 13, 2026

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit a2e087f
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/69bbc2e026cebf00084f276b
😎 Deploy Preview https://deploy-preview-2121--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 13, 2026

Open in StackBlitz

@wxt-dev/analytics

npm i https://pkg.pr.new/@wxt-dev/analytics@2121

@wxt-dev/auto-icons

npm i https://pkg.pr.new/@wxt-dev/auto-icons@2121

@wxt-dev/browser

npm i https://pkg.pr.new/@wxt-dev/browser@2121

@wxt-dev/i18n

npm i https://pkg.pr.new/@wxt-dev/i18n@2121

@wxt-dev/is-background

npm i https://pkg.pr.new/@wxt-dev/is-background@2121

@wxt-dev/module-react

npm i https://pkg.pr.new/@wxt-dev/module-react@2121

@wxt-dev/module-solid

npm i https://pkg.pr.new/@wxt-dev/module-solid@2121

@wxt-dev/module-svelte

npm i https://pkg.pr.new/@wxt-dev/module-svelte@2121

@wxt-dev/module-vue

npm i https://pkg.pr.new/@wxt-dev/module-vue@2121

@wxt-dev/runner

npm i https://pkg.pr.new/@wxt-dev/runner@2121

@wxt-dev/storage

npm i https://pkg.pr.new/@wxt-dev/storage@2121

@wxt-dev/unocss

npm i https://pkg.pr.new/@wxt-dev/unocss@2121

@wxt-dev/webextension-polyfill

npm i https://pkg.pr.new/@wxt-dev/webextension-polyfill@2121

wxt

npm i https://pkg.pr.new/wxt@2121

commit: a2e087f

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.19%. Comparing base (c6c9f65) to head (a2e087f).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PatrykKuniczak PatrykKuniczak enabled auto-merge (squash) February 13, 2026 15:12
Copy link
Member

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops, meant to request changes.

@PatrykKuniczak
Copy link
Collaborator Author

@aklinker1 Now it should be good

@PatrykKuniczak
Copy link
Collaborator Author

@aklinker1 Conflicts resolved 😄

@PatrykKuniczak PatrykKuniczak force-pushed the chore/add-new-types-for-i18n branch from 11dfd0e to e254767 Compare March 10, 2026 19:57
@PatrykKuniczak
Copy link
Collaborator Author

@aklinker1 Again, let's check it :)

@aklinker1
Copy link
Member

aklinker1 commented Mar 18, 2026

@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

@PatrykKuniczak
Copy link
Collaborator Author

but I can't tell what your changes to the public APIs/types are doing

What do you mean?

Copy link
Member

@aklinker1 aklinker1 Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled out all the changes to this file to #2201, they look good to me with a few tweaks.

Comment on lines -10 to +5
export function createI18n<
T extends I18nStructure = DefaultI18nStructure,
>(): I18n<T> {
const t = (key: string, ...args: any[]) => {
export function createI18n<T extends I18nStructure>(): I18n<T> {
Copy link
Member

@aklinker1 aklinker1 Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@aklinker1
Copy link
Member

aklinker1 commented Mar 18, 2026

What do you mean?

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 any from the package?

If so, your PR title and description don't mention that at all.

@PatrykKuniczak
Copy link
Collaborator Author

What do you mean?

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 any from the package?

If so, your PR title and description don't mention that at all.

Ooo yeah, i've wanted to avoid any, i'll se e your PR and the we'll be able to discuss rest changes from this one

@PatrykKuniczak PatrykKuniczak force-pushed the chore/add-new-types-for-i18n branch from e254767 to a548c55 Compare March 19, 2026 08:37
@PatrykKuniczak
Copy link
Collaborator Author

@aklinker1 I hope now, it's more readable 😄

@PatrykKuniczak PatrykKuniczak changed the title chore: Add new types for i18n chore: Extends i18n types to avoid any Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants