-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Open
Labels
[Package] i18n/packages/i18n/packages/i18n[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
Description
#70843 and #70434 have created unnecessary friction for i18n functions. Reassigning the values to the result of i18n functions is a common and legitimate case, and this PR breaks that.
The return of i18n functions should be a string
, not a string literal, because at runtime, it's not actually the English text that the type depicts. There is no use of that generic for these i18n functions.
Step-by-step reproduction instructions
This code should not have any TS errors
type Code = 'code-1' | 'code-2';
const errorCode: Code = 'code-1';
let message = __( 'Some default message' );
switch ( errorCode ) {
case 'code-1':
// This reassignment errs
message = __( 'An error occurred' );
// ^^^^^^^ "Type 'TranslatableText<"An error occurred">' is not assignable to type 'TranslatableText<"Some default message">'."
break;
default:
message = __( 'Unknown error occurred' );
}
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
- Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- Yes
Please confirm which theme type you used for testing.
- Block
- Classic
- Hybrid (e.g. classic with theme.json)
- Not sure
Metadata
Metadata
Assignees
Labels
[Package] i18n/packages/i18n/packages/i18n[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended