Skip to content

Commit

Permalink
Add types for confi/types
Browse files Browse the repository at this point in the history
- Adds the folder test-d/ to contain the types
- we are using tsd to check the types
- Added a test:types script to package.json
- Apparently we need a root index.d.ts for tsd to work
  tsdjs/tsd#32 (comment)
  • Loading branch information
peterMuriuki committed Apr 14, 2020
1 parent 6c1d2bd commit c413735
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
Empty file added index.d.ts
Empty file.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"yup": "^0.27.0"
},
"scripts": {
"test:types": "yarn run tsd",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "TZ=UTC react-scripts test --env=jest-environment-jsdom-sixteen",
Expand All @@ -84,6 +85,9 @@
"test:coverage": "set CI=true && react-scripts test --coverage",
"coveralls": "set CI=true && yarn test --runInBand --verbose --coverage=true --forceExit --detectOpenHandles && cat ./coverage/lcov.info | coveralls"
},
"tsd": {
"directory": "src/test-d"
},
"jest": {
"collectCoverageFrom": [
"src/**/*.{ts,tsx}",
Expand Down
Empty file added src/test-d/index.d.ts
Empty file.
48 changes: 48 additions & 0 deletions src/test-d/types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'react';
import { expectAssignable, expectType } from 'tsd';
import {
adminLayerColorsType,
ADMN0_PCODE,
EmptyObject,
FlexComponent,
GREEN_THRESHOLD,
JurisdictionTypes,
ORANGE_THRESHOLD,
YELLOW_THRESHOLD,
} from '../configs/types';

expectType<EmptyObject>({});

expectType<GREEN_THRESHOLD>(0.9);
expectType<YELLOW_THRESHOLD>(0.2);
expectType<ORANGE_THRESHOLD>(0.8);

expectAssignable<ADMN0_PCODE>('TH');
expectAssignable<ADMN0_PCODE>('ZM');
expectAssignable<ADMN0_PCODE>('ra Zambia');
expectAssignable<ADMN0_PCODE>('NA');
expectAssignable<ADMN0_PCODE>('BW');
expectAssignable<ADMN0_PCODE>('Chadiza');
expectAssignable<ADMN0_PCODE>('Sinda');
expectAssignable<ADMN0_PCODE>('Katete');
expectAssignable<ADMN0_PCODE>('Siavonga');
expectAssignable<ADMN0_PCODE>('Lop Buri');
expectAssignable<ADMN0_PCODE>('Oddar Meanchey Province');
expectAssignable<ADMN0_PCODE>('Lusaka');

expectAssignable<adminLayerColorsType>('black');
expectAssignable<adminLayerColorsType>('red');
expectAssignable<adminLayerColorsType>('orange');
expectAssignable<adminLayerColorsType>('yellow');
expectAssignable<adminLayerColorsType>('green');

expectAssignable<JurisdictionTypes>('administrative');
expectAssignable<JurisdictionTypes>('operational');

class SampleComponent extends React.Component<{}> {
public render() {
return null;
}
}

expectAssignable<FlexComponent<{}>>(SampleComponent);
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"noEmit": true,
"jsx": "preserve"
},
"include": ["src"]
}
"include": ["src", "index.d.ts"]
}

0 comments on commit c413735

Please sign in to comment.