File tree Expand file tree Collapse file tree 2 files changed +13
-13
lines changed
types/preview/@ember/template Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change 1- import { SafeString } from '@ember/template/-private/handlebars' ;
2- import { htmlSafe , isHTMLSafe } from '@ember/template' ;
1+ import { htmlSafe , isHTMLSafe , SafeString } from '@ember/template' ;
32import { expectTypeOf } from 'expect-type' ;
43
5- const handlebarsSafeString : SafeString = htmlSafe ( 'lorem ipsum...' ) ;
6- expectTypeOf ( htmlSafe ( 'lorem ipsum...' ) ) . toEqualTypeOf < SafeString > ( ) ;
7- // @ts -expect-error
8- const regularString : string = htmlSafe ( 'lorem ipsum...' ) ;
9-
4+ let trusted = htmlSafe ( 'lorem ipsum...' ) ;
5+ expectTypeOf ( trusted ) . toEqualTypeOf < SafeString > ( ) ;
6+ expectTypeOf ( trusted ) . not . toBeString ( ) ;
107expectTypeOf ( isHTMLSafe ) . guards . toEqualTypeOf < SafeString > ( ) ;
8+ expectTypeOf ( trusted . toHTML ( ) ) . toBeString ( ) ;
9+ expectTypeOf ( trusted . toString ( ) ) . toBeString ( ) ;
1110
12- function isSafeTest ( a : string | SafeString ) {
13- if ( isHTMLSafe ( a ) ) {
14- a = a . toString ( ) ;
15- }
11+ expectTypeOf < SafeString > ( ) . toMatchTypeOf < {
12+ toString ( ) : string ;
13+ toHTML ( ) : string ;
14+ } > ( ) ;
1615
17- a . toLowerCase ( ) ;
18- }
16+ // @ts -expect-error -- we do not allow construction by exporting only the type.
17+ new SafeString ( 'whatever' ) ;
Original file line number Diff line number Diff line change 11declare module '@ember/template' {
22 import { SafeString } from '@ember/template/-private/handlebars' ;
3+ export type { SafeString } ;
34 export function htmlSafe ( str : string ) : SafeString ;
45 export function isHTMLSafe ( str : unknown ) : str is SafeString ;
56}
You can’t perform that action at this time.
0 commit comments