From ac8a9d309ef00ec2717bdc88b2820e0ff7ee4af3 Mon Sep 17 00:00:00 2001 From: Seally Date: Thu, 11 Jul 2019 03:43:04 +0700 Subject: [PATCH] [fluent] Add 'undefined' to return type of FluentBundle.getMessage() (#36671) * Fix(fluent): add 'undefined' to return type of FluentBundle.getMessage(). * Fix(fluent): Change parameter of FluentBundle.hasMessage() to 'id' to match API docs. --- types/fluent/fluent-tests.ts | 6 +++--- types/fluent/index.d.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/types/fluent/fluent-tests.ts b/types/fluent/fluent-tests.ts index 17fb065f7d..1e9905ca06 100644 --- a/types/fluent/fluent-tests.ts +++ b/types/fluent/fluent-tests.ts @@ -13,7 +13,7 @@ if (errors1.length) { const welcome = bundle1.getMessage('welcome'); -bundle1.format(welcome, { name: 'Anna' }); +bundle1.format(welcome || [], { name: 'Anna' }); // FluentBundle constructor examples: const bundle2 = new FluentBundle(['en-US']); @@ -41,8 +41,8 @@ bundle2.getMessage('foo'); const errors2: Array = []; bundle1.addMessages('hello = Hello, { $name }!'); const hello = bundle2.getMessage('hello'); -bundle3.format(hello, { name: 'Jane' }, errors2); -bundle3.format(hello, undefined, errors2); +bundle3.format(hello || [], { name: 'Jane' }, errors2); +bundle3.format(hello || [], undefined, errors2); for (const [id, message] of bundle1.messages) { bundle1.getMessage(id); diff --git a/types/fluent/index.d.ts b/types/fluent/index.d.ts index 33d616cdd2..6b5d88e6c3 100644 --- a/types/fluent/index.d.ts +++ b/types/fluent/index.d.ts @@ -30,9 +30,9 @@ export class FluentBundle { constructor(locales: string | string[], options?: FluentBundleContructorOptions); locales: string[]; messages: IterableIterator<[string, FluentNode[]]>; - hasMessage(source: string): boolean; + hasMessage(id: string): boolean; addMessages(source: string): string[]; - getMessage(id: string): FluentNode[]; + getMessage(id: string): FluentNode[] | undefined; format(message: FluentNode[], args?: object, errors?: Array): string; addResource(res: FluentResource): string[]; }