From b9327627c6acfdd34ebd964aae6017256486dcf5 Mon Sep 17 00:00:00 2001 From: Joren Broekema Date: Mon, 14 Sep 2020 18:36:07 +0200 Subject: [PATCH] fix(form-core): align on common Intl type formatOptions --- .changeset/tiny-ears-agree.md | 6 ++++++ packages/form-core/src/FormatMixin.js | 5 ++--- packages/form-core/types/FormatMixinTypes.d.ts | 12 ++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 .changeset/tiny-ears-agree.md diff --git a/.changeset/tiny-ears-agree.md b/.changeset/tiny-ears-agree.md new file mode 100644 index 000000000..d5511ea58 --- /dev/null +++ b/.changeset/tiny-ears-agree.md @@ -0,0 +1,6 @@ +--- +'@lion/form-core': patch +'@lion/localize': patch +--- + +These packages were using out of sync type definitions for FormatOptions, and the types were missing a bunch of options that Intl would normally accept. We now extend Intl's NumberFormatOptions and DateTimeFormatOptions properly, so we always have the right types and are more consistent on it. diff --git a/packages/form-core/src/FormatMixin.js b/packages/form-core/src/FormatMixin.js index 74bbb6af8..644f913a8 100644 --- a/packages/form-core/src/FormatMixin.js +++ b/packages/form-core/src/FormatMixin.js @@ -7,7 +7,7 @@ import { ValidateMixin } from './validate/ValidateMixin.js'; /** * @typedef {import('../types/FormatMixinTypes').FormatMixin} FormatMixin - * @typedef {import('../types/FormatMixinTypes').FormatOptions} FormatOptions + * @typedef {import('@lion/localize/types/LocalizeMixinTypes').FormatNumberOptions} FormatOptions */ // For a future breaking release: @@ -357,8 +357,7 @@ const FormatMixinImplementation = superclass => constructor() { super(); this.formatOn = 'change'; - /** @type {FormatOptions} */ - this.formatOptions = {}; + this.formatOptions = /** @type {FormatOptions} */ ({}); } connectedCallback() { diff --git a/packages/form-core/types/FormatMixinTypes.d.ts b/packages/form-core/types/FormatMixinTypes.d.ts index 7855ecdce..5b4ac86ab 100644 --- a/packages/form-core/types/FormatMixinTypes.d.ts +++ b/packages/form-core/types/FormatMixinTypes.d.ts @@ -1,24 +1,20 @@ import { Constructor } from '@open-wc/dedupe-mixin'; import { LitElement } from '@lion/core'; +import { FormatNumberOptions } from '@lion/localize/types/LocalizeMixinTypes'; import { ValidateHost } from './validate/ValidateMixinTypes'; import { FormControlHost } from './FormControlMixinTypes'; -export declare interface FormatOptions { - locale?: string; - decimalSeparator?: string; -} - export declare class FormatHost { formattedValue: string; serializedValue: string; formatOn: string; - formatOptions: FormatOptions; + formatOptions: FormatNumberOptions; value: string; __preventRecursiveTrigger: boolean; __isHandlingUserInput: boolean; - parser(v: string, opts: FormatOptions): unknown; - formatter(v: unknown, opts: FormatOptions): string; + parser(v: string, opts: FormatNumberOptions): unknown; + formatter(v: unknown, opts: FormatNumberOptions): string; serializer(v: unknown): string; deserializer(v: string): unknown;