-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@formatjs/intl): fix type checker errors with TypeScript 4.9 (#3916)
Supersedes #3912 Fixes #3905 Fixes #3910 This PR fixes the type checking issue of `MessageIds` and `Locale` under TypeScript 4.9. It may be a TypeScript bug, because this does not work: ```ts type MessageIds = FormatjsIntl.Message extends {ids: string} ? FormatjsIntl.Message['ids'] : string ``` But this works: ```ts type _Message = FormatjsIntl.Message type MessageIds = _Message extends {ids: string} ? _Message['ids'] : string ``` 🤷 The only difference is aliasing the type from the namespace. --- I also added a `tsd` test to verify that the global type override works as expected.
- Loading branch information
1 parent
9336c9a
commit 36d0437
Showing
6 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {expectType} from 'tsd' | ||
import {MessageDescriptor, ResolvedIntlConfig} from '../src/types' | ||
|
||
// Example type overrides | ||
declare global { | ||
namespace FormatjsIntl { | ||
interface Message { | ||
ids: 'a' | 'b' | ||
} | ||
interface IntlConfig { | ||
locale: 'en-US' | 'zh-CN' | ||
} | ||
} | ||
} | ||
|
||
// Check that the type overrides actually work. | ||
expectType<'a' | 'b'>(null as any as NonNullable<MessageDescriptor['id']>) | ||
expectType<'en-US' | 'zh-CN'>(null as any as ResolvedIntlConfig['locale']) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters