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' ;
3
2
import { expectTypeOf } from 'expect-type' ;
4
3
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 ( ) ;
10
7
expectTypeOf ( isHTMLSafe ) . guards . toEqualTypeOf < SafeString > ( ) ;
8
+ expectTypeOf ( trusted . toHTML ( ) ) . toBeString ( ) ;
9
+ expectTypeOf ( trusted . toString ( ) ) . toBeString ( ) ;
11
10
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
+ } > ( ) ;
16
15
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 1
1
declare module '@ember/template' {
2
2
import { SafeString } from '@ember/template/-private/handlebars' ;
3
+ export type { SafeString } ;
3
4
export function htmlSafe ( str : string ) : SafeString ;
4
5
export function isHTMLSafe ( str : unknown ) : str is SafeString ;
5
6
}
You can’t perform that action at this time.
0 commit comments