1
1
// This a test file to check if typescript is working properly
2
-
2
+ import React from 'react' ;
3
3
import NiceModal , { useModal , antdModalV5 } from '@ebay/nice-modal-react' ;
4
4
5
5
const MyModal1 = NiceModal . create ( ( { p1, p2 } : { p1 : string ; p2 : number } ) => {
@@ -22,16 +22,20 @@ const MyModal2 = NiceModal.create(() => {
22
22
) ;
23
23
} ) ;
24
24
25
- NiceModal . register ( 'modal-1' , MyModal1 , { p2 : 1 } ) ;
25
+ NiceModal . register ( 'modal-1' , MyModal1 , { p2 : 1 , p1 : 'abc' } ) ;
26
26
27
27
export default function TsTest ( ) {
28
- const modal1 = useModal ( MyModal1 , { p3 : 'foo ' , p2 : 123 } ) ;
28
+ const modal1 = useModal ( MyModal1 , { p1 : 'abc ' , p2 : 123 } ) ;
29
29
modal1 . show ( { p1 : 'foo' , p2 : 123 , p4 : 'hello' } ) ; // expected: p4 should not be accepted
30
+ modal1 . show ( { p2 : 1 , p1 : '1' } ) ;
31
+ modal1 . show ( { p2 : 1 , p1 : 1 } ) ; // expected: p1 should be string
32
+ modal1 . show ( ) ;
30
33
31
34
NiceModal . show ( MyModal1 ) ; // valid?
32
35
NiceModal . show ( MyModal1 , { p1 : 'foo' , p2 : 123 } ) ; // valid
33
36
NiceModal . show ( MyModal1 , { p1 : 'foo' , p2 : '123' } ) ; // expected ts error: p2 should be number
34
- NiceModal . show ( MyModal1 , { p1 : 'foo' } ) ; // unexpected ts error: p2 is already set when register
37
+ NiceModal . show ( MyModal1 , { p1 : 'foo' } ) ;
38
+ NiceModal . show ( MyModal1 , { p2 : 123 } ) ;
35
39
36
40
const modal1_1 = useModal ( 'modal-1' , { p3 : 'foo' , p2 : 123 } ) ;
37
41
modal1_1 . show ( ) ;
0 commit comments