From 28628363db3b4e6a4cd021b0e338ed2b59d16641 Mon Sep 17 00:00:00 2001 From: Ruslan Hrabovyi Date: Tue, 29 Jan 2019 00:52:25 +0200 Subject: [PATCH] [@ember/string] Use type predicate as "isHTMLSafe" result --- types/ember__string/ember__string-tests.ts | 10 +++++++++- types/ember__string/index.d.ts | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/types/ember__string/ember__string-tests.ts b/types/ember__string/ember__string-tests.ts index 1f045b849d..500c67546e 100644 --- a/types/ember__string/ember__string-tests.ts +++ b/types/ember__string/ember__string-tests.ts @@ -1,4 +1,4 @@ -import { dasherize, camelize, capitalize, classify, decamelize, htmlSafe, loc, underscore, w } from '@ember/string'; +import { dasherize, camelize, capitalize, classify, decamelize, htmlSafe, loc, underscore, w, isHTMLSafe } from '@ember/string'; import { SafeString } from 'handlebars'; dasherize(); // $ExpectError @@ -36,3 +36,11 @@ loc("_Hello %@ %@", ["John", "Smith"]); // $ExpectType string const handlebarsSafeString: SafeString = htmlSafe('lorem ipsum...'); htmlSafe('lorem ipsum...'); // $ExpectType SafeString const regularString: string = htmlSafe('lorem ipsum...'); // $ExpectError + +function isSafeTest(a: string|Handlebars.SafeString) { + if (isHTMLSafe(a)) { + a = a.toString(); + } + + camelize(a); +} diff --git a/types/ember__string/index.d.ts b/types/ember__string/index.d.ts index 8a2a46c022..66b5199bfd 100644 --- a/types/ember__string/index.d.ts +++ b/types/ember__string/index.d.ts @@ -11,8 +11,8 @@ export function capitalize(str: string): string; export function classify(str: string): string; export function dasherize(str: string): string; export function decamelize(str: string): string; -export function htmlSafe(str: string): Handlebars.SafeString; -export function isHTMLSafe(str: string): boolean; +export function htmlSafe(str: string): SafeString; +export function isHTMLSafe(str: any): str is SafeString; export function loc(template: string, args?: string[]): string; export function underscore(str: string): string; export function w(str: string): string[];