diff --git a/type-tests/@ember/template-tests.ts b/type-tests/@ember/template-tests.ts index 7c38e72387e..01f1b419cc4 100644 --- a/type-tests/@ember/template-tests.ts +++ b/type-tests/@ember/template-tests.ts @@ -1,18 +1,17 @@ -import { SafeString } from '@ember/template/-private/handlebars'; -import { htmlSafe, isHTMLSafe } from '@ember/template'; +import { htmlSafe, isHTMLSafe, SafeString } from '@ember/template'; import { expectTypeOf } from 'expect-type'; -const handlebarsSafeString: SafeString = htmlSafe('lorem ipsum...'); -expectTypeOf(htmlSafe('lorem ipsum...')).toEqualTypeOf(); -// @ts-expect-error -const regularString: string = htmlSafe('lorem ipsum...'); - +let trusted = htmlSafe('lorem ipsum...'); +expectTypeOf(trusted).toEqualTypeOf(); +expectTypeOf(trusted).not.toBeString(); expectTypeOf(isHTMLSafe).guards.toEqualTypeOf(); +expectTypeOf(trusted.toHTML()).toBeString(); +expectTypeOf(trusted.toString()).toBeString(); -function isSafeTest(a: string | SafeString) { - if (isHTMLSafe(a)) { - a = a.toString(); - } +expectTypeOf().toMatchTypeOf<{ + toString(): string; + toHTML(): string; +}>(); - a.toLowerCase(); -} +// @ts-expect-error -- we do not allow construction by exporting only the type. +new SafeString('whatever'); diff --git a/types/preview/@ember/template/index.d.ts b/types/preview/@ember/template/index.d.ts index 32b7d70da6f..be2c034b66e 100644 --- a/types/preview/@ember/template/index.d.ts +++ b/types/preview/@ember/template/index.d.ts @@ -1,5 +1,6 @@ declare module '@ember/template' { import { SafeString } from '@ember/template/-private/handlebars'; + export type { SafeString }; export function htmlSafe(str: string): SafeString; export function isHTMLSafe(str: unknown): str is SafeString; }