move buildInitial to ts

This commit is contained in:
Yanick Champoux 2019-10-23 12:47:11 -04:00
parent 3486b71acc
commit 199ab2ba31
6 changed files with 38 additions and 14 deletions

1
index.d.ts vendored Normal file
View File

@ -0,0 +1 @@

17
index.test-d.ts Normal file
View File

@ -0,0 +1,17 @@
import { expectType, expectError } from 'tsd';
import buildInitial from './src/buildInitial';
expectType<{}>(buildInitial());
type MyState = {
foo: {
bar: number
},
baz: string,
}
expectType<MyState>(buildInitial<MyState>());
expectError( buildInitial<MyState>({ foo: { bar: "potato" } }) );

View File

@ -1,8 +0,0 @@
import fp from 'lodash/fp';
export default function buildInitial(
initial= {},
subduxes = {},
) {
return fp.isPlainObject(initial) ? fp.mergeAll([subduxes, initial]) : initial;
}

11
src/buildInitial/index.ts Normal file
View File

@ -0,0 +1,11 @@
import fp from 'lodash/fp';
function buildInitial<S extends object>( initial?: Partial<S>, subduxes?: Partial<S> ): S;
function buildInitial(
initial = {},
subduxes = {} ,
) {
return fp.isPlainObject(initial) ? fp.mergeAll([subduxes, initial]) : initial;
}
export default buildInitial;

View File

@ -1,20 +1,23 @@
{
"include": [
"./src/**/*"
],
"compilerOptions": {
/* Basic Options */
"incremental": true, /* Enable incremental compilation */
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [ "dom", "es2019" ], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
"allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"declaration": false, /* Generates corresponding '.d.ts' file. */
"declarationMap": false, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": false, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
//"composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
"removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
@ -24,7 +27,7 @@
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */