Skip to content

Commit

Permalink
fix: update typescript version and fix type error (#1277)
Browse files Browse the repository at this point in the history
* fix: update typescript version and fix type error

* fix: update typescript version and fix type error

* fix test error and update Snapshot due to the vue version update
  • Loading branch information
littleboarx authored Dec 23, 2022
1 parent a1d7259 commit 250446b
Show file tree
Hide file tree
Showing 22 changed files with 344 additions and 298 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"@types/node": "^16.18.8",
"@typescript-eslint/eslint-plugin": "^5.46.0",
"@typescript-eslint/parser": "^5.46.0",
"@vue/server-renderer": "^3.2.4",
"algoliasearch": "^4.9.0",
"api-docs-gen": "^0.4.0",
"brotli": "^1.3.2",
Expand Down Expand Up @@ -133,14 +132,14 @@
"textlint-rule-write-good": "^2.0.0",
"trash-cli": "^5.0.0",
"ts-jest": "^26.5.4",
"typescript": "4.2.3",
"typescript": "^4.9.4",
"vitepress": "^1.0.0-alpha.4",
"vue": "^3.2.4",
"vue": "^3.2.45",
"vue-i18n": "workspace:*"
},
"peerDependencies": {
"@microsoft/api-extractor": "7.15.2",
"typescript": "4.2.3"
"typescript": "^4.9.4"
},
"engines": {
"node": ">= 14"
Expand Down Expand Up @@ -182,7 +181,7 @@
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"vue": "3.2.20",
"vue": "3.2.45",
"vite": "2.6.14"
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core-base/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type LocaleMessageType<T, Message = string> = T extends string
? LocaleMessageDictionary<P, Message>
: T extends (...args: infer Arguments) => any
? (...args: Arguments) => ReturnType<T>
: T extends Record<string, any>
: T extends Record<string, unknown>
? LocaleMessageDictionary<T, Message>
: T extends Array<T>
? { [K in keyof T]: T[K] }
Expand Down Expand Up @@ -107,7 +107,7 @@ export type MessageCompiler<Message = string> = (
// prettier-ignore
export interface CoreOptions<
Message = string,
Schema extends
Schema extends
{
message?: unknown
datetime?: unknown
Expand Down
12 changes: 6 additions & 6 deletions packages/core-base/src/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ export interface DateTimeOptions<Key = string, Locales = Locale>
*/

export function datetime<
Context extends CoreContext<Message, {}, Context['datetimeFormats'], {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Message = string
>(
context: Context,
value: number | string | Date
): string | number | Intl.DateTimeFormatPart[]

export function datetime<
Context extends CoreContext<Message, {}, Context['datetimeFormats'], {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Value extends number | string | Date = number,
Key extends string = string,
ResourceKeys extends PickupFormatKeys<
Expand All @@ -134,7 +134,7 @@ export function datetime<
): string | number | Intl.DateTimeFormatPart[]

export function datetime<
Context extends CoreContext<Message, {}, Context['datetimeFormats'], {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Value extends number | string | Date = number,
Key extends string = string,
ResourceKeys extends PickupFormatKeys<
Expand All @@ -152,7 +152,7 @@ export function datetime<
): string | number | Intl.DateTimeFormatPart[]

export function datetime<
Context extends CoreContext<Message, {}, Context['datetimeFormats'], {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Value extends number | string | Date = number,
Key extends string = string,
ResourceKeys extends PickupFormatKeys<
Expand All @@ -170,7 +170,7 @@ export function datetime<
): string | number | Intl.DateTimeFormatPart[]

export function datetime<
Context extends CoreContext<Message, {}, Context['datetimeFormats'], {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Value extends number | string | Date = number,
Key extends string = string,
ResourceKeys extends PickupFormatKeys<
Expand All @@ -190,7 +190,7 @@ export function datetime<

// implementation of `datetime` function
export function datetime<
Context extends CoreContext<Message, {}, Context['datetimeFormats'], {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Message = string
>(
context: Context,
Expand Down
12 changes: 6 additions & 6 deletions packages/core-base/src/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ export interface NumberOptions<Key = string, Locales = Locale>
*/

export function number<
Context extends CoreContext<Message, {}, {}, Context['numberFormats']>,
Context extends CoreContext<Message, {}, {}, {}>,
Message = string
>(context: Context, value: number): string | number | Intl.NumberFormatPart[]

export function number<
Context extends CoreContext<Message, {}, {}, Context['numberFormats']>,
Context extends CoreContext<Message, {}, {}, {}>,
Value extends number = number,
Key extends string = string,
ResourceKeys extends PickupFormatKeys<
Expand All @@ -129,7 +129,7 @@ export function number<
): string | number | Intl.NumberFormatPart[]

export function number<
Context extends CoreContext<Message, {}, {}, Context['numberFormats']>,
Context extends CoreContext<Message, {}, {}, {}>,
Value extends number = number,
Key extends string = string,
ResourceKeys extends PickupFormatKeys<
Expand All @@ -147,7 +147,7 @@ export function number<
): string | number | Intl.NumberFormatPart[]

export function number<
Context extends CoreContext<Message, {}, {}, Context['numberFormats']>,
Context extends CoreContext<Message, {}, {}, {}>,
Value extends number = number,
Key extends string = string,
ResourceKeys extends PickupFormatKeys<
Expand All @@ -165,7 +165,7 @@ export function number<
): string | number | Intl.NumberFormatPart[]

export function number<
Context extends CoreContext<Message, {}, {}, Context['numberFormats']>,
Context extends CoreContext<Message, {}, {}, {}>,
Value extends number = number,
Key extends string = string,
ResourceKeys extends PickupFormatKeys<
Expand All @@ -185,7 +185,7 @@ export function number<

// implementation of `number` function
export function number<
Context extends CoreContext<Message, {}, {}, Context['numberFormats']>,
Context extends CoreContext<Message, {}, {}, {}>,
Message = string
>(
context: Context,
Expand Down
3 changes: 1 addition & 2 deletions packages/core-base/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function pluralDefault(choice: number, choicesLength: number): number {
return choice ? Math.min(choice, 2) : 0
}

function getPluralIndex<T>(options: MessageContextOptions<T>): number {
function getPluralIndex<T, N>(options: MessageContextOptions<T, N>): number {
// prettier-ignore
const index = isNumber(options.pluralIndex)
? options.pluralIndex
Expand Down Expand Up @@ -164,7 +164,6 @@ export function createMessageContext<T = string, N = {}>(
options: MessageContextOptions<T, N> = {}
): MessageContext<T> {
const locale = options.locale

const pluralIndex = getPluralIndex(options)
const pluralRule =
isObject(options.pluralRules) &&
Expand Down
28 changes: 14 additions & 14 deletions packages/core-base/src/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export interface TranslateOptions<Locales = Locale> {
*/

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -170,7 +170,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -183,7 +183,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -197,7 +197,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -210,7 +210,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -224,7 +224,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -237,7 +237,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -251,7 +251,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -265,7 +265,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -279,7 +279,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -292,7 +292,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -306,7 +306,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -320,7 +320,7 @@ export function translate<
): MessageType<Message> | number

export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Key extends string = string,
ResourceKeys extends PickupKeys<Context['messages']> = PickupKeys<
Context['messages']
Expand All @@ -335,7 +335,7 @@ export function translate<

// implementation of `translate` function
export function translate<
Context extends CoreContext<Message, Context['messages'], {}, {}>,
Context extends CoreContext<Message, {}, {}, {}>,
Message = string
>(context: Context, ...args: unknown[]): MessageType<Message> | number {
const {
Expand Down
6 changes: 5 additions & 1 deletion packages/shared/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ export let measure: (

if (__DEV__) {
const perf = inBrowser && window.performance

if (
perf &&
perf.mark &&
perf.measure &&
perf.clearMarks &&
// @ts-ignore browser compat
perf.clearMeasures
) {
mark = (tag: string): void => perf.mark(tag)
mark = (tag: string): void => {
perf.mark(tag)
}
measure = (name: string, startTag: string, endTag: string): void => {
perf.measure(name, startTag, endTag)
perf.clearMarks(startTag)
Expand Down
6 changes: 4 additions & 2 deletions packages/vue-i18n-core/src/components/DatetimeFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ export const DatetimeFormat = /* #__PURE__*/ /*defineComponent */ {
setup(props: any, context: any): any {
const i18n =
props.i18n ||
(useI18n({ useScope: 'parent', __useComponent: true }) as Composer &
ComposerInternal)
(useI18n({
useScope: 'parent',
__useComponent: true
}) as unknown as Composer & ComposerInternal)

return renderFormatter<
FormattableProps<number | Date, Intl.DateTimeFormatOptions>,
Expand Down
6 changes: 4 additions & 2 deletions packages/vue-i18n-core/src/components/NumberFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export const NumberFormat = /* #__PURE__*/ /* defineComponent */ {
setup(props: any, context: any): any {
const i18n =
props.i18n ||
(useI18n({ useScope: 'parent', __useComponent: true }) as Composer &
ComposerInternal)
(useI18n({
useScope: 'parent',
__useComponent: true
}) as unknown as Composer & ComposerInternal)

return renderFormatter<
FormattableProps<number, Intl.NumberFormatOptions>,
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-i18n-core/src/components/Translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const Translation = /* #__PURE__*/ /* defineComponent */ {
(useI18n({
useScope: props.scope as 'global' | 'parent',
__useComponent: true
}) as Composer & ComposerInternal)
}) as unknown as Composer & ComposerInternal)

return (): VNodeChild => {
const keys = Object.keys(slots).filter(key => key !== '_')
Expand Down
Loading

0 comments on commit 250446b

Please sign in to comment.