Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡improvement(types): typed autocomplete in date and number format options #485

Merged
merged 2 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 43 additions & 27 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,55 @@ declare namespace VueI18n {
interface LocaleMessageArray { [index: number]: LocaleMessage; }
interface LocaleMessages { [key: string]: LocaleMessageObject; }
type TranslateResult = string | LocaleMessages;
interface DateTimeFormatOptions {
year?: string;
month?: string;
day?: string;
hour?: string;
minute?: string;
second?: string;
weekday?: string;
hour12?: boolean;
era?: string;
timeZone?: string;
timeZoneName?: string;
localeMatcher?: string;
formatMatcher?: string;

type LocaleMatcher = 'lookup' | 'best-fit';
type FormatMatcher = 'basic' | 'best-fit';

type DateTimeHumanReadable = 'long' | 'short' | 'narrow';
type DateTimeDigital = 'numeric' | '2-digit';

interface SpecificDateTimeFormatOptions extends Intl.DateTimeFormatOptions {
year?: DateTimeDigital;
month?: DateTimeDigital | DateTimeHumanReadable;
day?: DateTimeDigital;
hour?: DateTimeDigital;
minute?: DateTimeDigital;
second?: DateTimeDigital;
weekday?: DateTimeHumanReadable;
era?: DateTimeHumanReadable;
timeZoneName?: 'long' | 'short';
localeMatcher?: LocaleMatcher;
formatMatcher?: FormatMatcher;
}

type DateTimeFormatOptions = Intl.DateTimeFormatOptions | SpecificDateTimeFormatOptions;

interface DateTimeFormat { [key: string]: DateTimeFormatOptions; }
interface DateTimeFormats { [key: string]: DateTimeFormat; }
interface DateTimeFormats { [locale: string]: DateTimeFormat; }
type DateTimeFormatResult = string;
interface NumberFormatOptions {
style?: string;

type CurrencyDisplay = 'symbol' | 'code' | 'name';

interface SpecificNumberFormatOptions extends Intl.NumberFormatOptions {
style?: 'decimal' | 'percent';
currency?: string;
currencyDisplay?: string;
useGrouping?: boolean;
minimumIntegerDigits?: number;
minimumFractionDigits?: number;
maximumFractionDigits?: number;
minimumSignificantDigits?: number;
maximumSignificantDigits?: number;
localeMatcher?: string;
formatMatcher?: string;
currencyDisplay?: CurrencyDisplay;
localeMatcher?: LocaleMatcher;
formatMatcher?: FormatMatcher;
}

interface CurrencyNumberFormatOptions extends Intl.NumberFormatOptions {
style: 'currency';
currency: string; // Obligatory if style is 'currency'
currencyDisplay?: CurrencyDisplay;
localeMatcher?: LocaleMatcher;
formatMatcher?: FormatMatcher;
}

type NumberFormatOptions = Intl.NumberFormatOptions | SpecificNumberFormatOptions | CurrencyNumberFormatOptions;

interface NumberFormat { [key: string]: NumberFormatOptions; }
interface NumberFormats { [key: string]: NumberFormat; }
interface NumberFormats { [locale: string]: NumberFormat; }
type NumberFormatResult = string;
type PluralizationRulesMap = {
/**
Expand Down
6 changes: 3 additions & 3 deletions types/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vue, { ComponentOptions } from 'vue';
import VueI18n from "../index";
import VueI18n, { DateTimeFormatOptions, NumberFormatOptions } from "../index";

/*
import * as VueI18n from 'vue-i18n';
Expand Down Expand Up @@ -27,11 +27,11 @@ VueI18n.availabilities; // $ExpectType IntlAvailability
const locale = 'locale';
const key = 'key';
const value = 'value';
const dateTimeFormatOptions = {
const dateTimeFormatOptions: DateTimeFormatOptions = {
year: '2-digit',
timeZone: 'Asia/Tokyo'
};
const numberFormatOptions = {
const numberFormatOptions: NumberFormatOptions = {
style: 'currency',
currency: 'JPY'
};
Expand Down