@@ -1482,6 +1482,78 @@ describe('parser', () => {
14821482 } ) ;
14831483 } ) ;
14841484
1485+ describe ( 'typescript strict mode' , ( ) => {
1486+ // typescript strict mode adds an extra `undefined` to enums
1487+ // may have other funky behavior
1488+ describe ( 'remove undefined from optional' , ( ) => {
1489+ const options = {
1490+ shouldExtractLiteralValuesFromEnum : true ,
1491+ shouldRemoveUndefinedFromOptional : true ,
1492+ savePropValueAsString : true
1493+ } ;
1494+ const parser = withCustomConfig (
1495+ // tsconfig with strict: true
1496+ path . join ( __dirname , '../../src/__tests__/data/tsconfig.json' ) ,
1497+ options
1498+ ) ;
1499+ it ( 'removes undefined from enums' , ( ) => {
1500+ const result = parser . parse (
1501+ fixturePath ( 'RemoveOptionalValuesFromEnum' )
1502+ ) ;
1503+ const expected = {
1504+ RemoveOptionalValuesFromEnum : {
1505+ sampleBoolean : { type : 'boolean' , required : false } ,
1506+ sampleEnum : {
1507+ raw : 'sampleEnum' ,
1508+ required : false ,
1509+ type : 'enum' ,
1510+ value : [
1511+ { value : '"one"' } ,
1512+ { value : '"two"' } ,
1513+ { value : '"three"' }
1514+ ]
1515+ } ,
1516+ sampleString : { type : 'string' , required : false }
1517+ }
1518+ } ;
1519+ checkComponent ( result , expected , false ) ;
1520+ } ) ;
1521+ it ( 'removes undefined from unions' , ( ) => {
1522+ const result = parser . parse (
1523+ fixturePath ( 'RemoveOptionalValuesFromUnion' )
1524+ ) ;
1525+ const expected = {
1526+ RemoveOptionalValuesFromUnion : {
1527+ sampleStringUnion : {
1528+ required : false ,
1529+ raw : '"string1" | "string2"' ,
1530+ type : 'enum' ,
1531+ value : [ { value : '"string1"' } , { value : '"string2"' } ]
1532+ } ,
1533+ sampleNumberUnion : {
1534+ required : false ,
1535+ raw : '1 | 2 | 3' ,
1536+ type : 'enum' ,
1537+ value : [ { value : '1' } , { value : '2' } , { value : '3' } ]
1538+ } ,
1539+ sampleMixedUnion : {
1540+ required : false ,
1541+ raw : '"string1" | "string2" | 1 | 2' ,
1542+ type : 'enum' ,
1543+ value : [
1544+ { value : '"string1"' } ,
1545+ { value : '"string2"' } ,
1546+ { value : '1' } ,
1547+ { value : '2' }
1548+ ]
1549+ }
1550+ }
1551+ } ;
1552+ check ( 'RemoveOptionalValuesFromUnion' , expected , false , null , options ) ;
1553+ } ) ;
1554+ } ) ;
1555+ } ) ;
1556+
14851557 describe ( 'parseWithProgramProvider' , ( ) => {
14861558 it ( 'should accept existing ts.Program instance' , ( ) => {
14871559 let programProviderInvoked = false ;
0 commit comments