Skip to content

Commit 50ed15b

Browse files
update types
1 parent 0f6ffde commit 50ed15b

File tree

11 files changed

+55
-42
lines changed

11 files changed

+55
-42
lines changed

src/cli/domain/get-mocked-plugins.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@ import strings from '../../resources/';
77
import { Logger } from '../logger';
88

99
interface MockedPlugin {
10-
register: Function;
11-
execute: Function;
10+
register: (options: unknown, dependencies: unknown, next: () => void) => void;
11+
execute: (...args: unknown[]) => unknown;
1212
}
1313

1414
interface PluginMock {
1515
name: string;
1616
register: {
17-
register: Function;
18-
execute: Function;
17+
register: (
18+
options: unknown,
19+
dependencies: unknown,
20+
next: () => void
21+
) => void;
22+
execute: (...args: unknown[]) => unknown;
1923
};
2024
}
2125

22-
const isMockValid = (plugin: unknown): plugin is MockedPlugin | Function => {
26+
const isMockValid = (
27+
plugin: unknown
28+
): plugin is MockedPlugin | ((...args: unknown[]) => unknown) => {
2329
const isFunction = typeof plugin === 'function';
2430
const isValidObject =
2531
!!plugin &&
@@ -34,9 +40,14 @@ const defaultRegister = (
3440
options: unknown,
3541
dependencies: unknown,
3642
next: () => void
37-
) => next();
43+
) => {
44+
next();
45+
};
3846

39-
const registerStaticMocks = (mocks, logger): PluginMock[] =>
47+
const registerStaticMocks = (
48+
mocks: Dictionary<string>,
49+
logger: Logger
50+
): PluginMock[] =>
4051
_.map(mocks, (mockedValue, pluginName) => {
4152
logger.ok(`├── ${pluginName} () => ${mockedValue}`);
4253

@@ -49,7 +60,11 @@ const registerStaticMocks = (mocks, logger): PluginMock[] =>
4960
};
5061
});
5162

52-
const registerDynamicMocks = (ocJsonLocation: string, mocks, logger) =>
63+
const registerDynamicMocks = (
64+
ocJsonLocation: string,
65+
mocks: Dictionary<string>,
66+
logger: Logger
67+
) =>
5368
_.map(mocks, (source, pluginName) => {
5469
let pluginMock;
5570
try {
@@ -87,7 +102,7 @@ const findPath = (
87102
if (pathToResolve === rootDir) {
88103
return undefined;
89104
} else {
90-
const getParent = pathToResolve =>
105+
const getParent = (pathToResolve: string) =>
91106
pathToResolve
92107
.split('/')
93108
.slice(0, -1)

src/cli/domain/init-template/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ export default function initTemplate(
1616
logger: Logger;
1717
},
1818
callback: Callback<{ ok: true }, string>
19-
) {
19+
): void {
2020
const { compiler, componentPath } = options;
2121
const compilerPath = path.join(componentPath, 'node_modules', compiler);
2222
const npmOptions = { initPath: componentPath, silent: true };
2323

2424
async.series(
2525
[
2626
cb => fs.ensureDir(componentPath, cb),
27-
cb => npm.init(npmOptions, cb),
28-
cb => installTemplate(options, cb),
29-
cb => scaffold(Object.assign(options, { compilerPath }), cb)
27+
cb => npm.init(npmOptions, cb as any),
28+
cb => installTemplate(options, cb as any),
29+
cb => scaffold(Object.assign(options, { compilerPath }), cb as any)
3030
],
31-
callback
31+
callback as any
3232
);
3333
}

src/cli/domain/init-template/install-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface Options {
1515
export default function installTemplate(
1616
options: Options,
1717
callback: Callback<{ ok: true }, string>
18-
) {
18+
): void {
1919
const { compiler, componentPath, logger, templateType } = options;
2020

2121
const npmOptions = {

src/cli/domain/mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function mock() {
77
return function(
88
params: { targetType: string; targetValue: string; targetName: string },
99
callback: (err: Error) => void
10-
) {
10+
): void {
1111
fs.readJson(settings.configFile.src, (err, localConfig) => {
1212
localConfig = localConfig || {};
1313

src/registry/routes/helpers/get-component-fallback.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Request, Response } from 'express';
2+
import { IncomingHttpHeaders } from 'http';
23
import request from 'minimal-request';
34
import url from 'url';
45
import { Component, Config } from '../../../types';
@@ -42,7 +43,7 @@ function getComponentFallbackForViewType(
4243
accept: 'application/json'
4344
}
4445
},
45-
(fallbackErr, fallbackResponse) => {
46+
(fallbackErr, fallbackResponse: string) => {
4647
if (fallbackErr === 304) {
4748
return res.status(304).send('');
4849
}
@@ -74,8 +75,8 @@ function getComponentFallbackForViewType(
7475

7576
export function getComponent(
7677
fallbackRegistryUrl: string,
77-
headers: Dictionary<string>,
78-
component: { name: string; version: string; parameters: Dictionary<string> },
78+
headers: IncomingHttpHeaders,
79+
component: { name: string; version: string; parameters: IncomingHttpHeaders },
7980
callback: (
8081
result:
8182
| {
@@ -84,7 +85,7 @@ export function getComponent(
8485
}
8586
| Component
8687
) => void
87-
) {
88+
): void {
8889
return request(
8990
{
9091
method: 'post',
@@ -93,13 +94,13 @@ export function getComponent(
9394
json: true,
9495
body: { components: [component] }
9596
},
96-
(err, res) => {
97+
(err, res: Component[]) => {
9798
if (err || !res || res.length === 0) {
9899
return callback({
99100
status: 404,
100101
response: {
101102
code: 'NOT_FOUND',
102-
error: err
103+
error: err as any
103104
}
104105
});
105106
}
@@ -115,7 +116,7 @@ export function getComponentPreview(
115116
res: Response,
116117
registryError: string | null,
117118
callback: ComponentCallback
118-
) {
119+
): void {
119120
getComponentFallbackForViewType(
120121
urlBuilder.componentPreview,
121122
conf,
@@ -132,7 +133,7 @@ export function getComponentInfo(
132133
res: Response,
133134
registryError: string | null,
134135
callback: ComponentCallback
135-
) {
136+
): void {
136137
getComponentFallbackForViewType(
137138
urlBuilder.componentInfo,
138139
conf,

src/registry/routes/plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Request, Response } from 'express';
22
import { Config } from '../../types';
33

44
export default function plugins(conf: Config) {
5-
return function(req: Request, res: Response) {
5+
return (req: Request, res: Response): void => {
66
if (conf.discovery) {
77
const plugins = Object.entries(conf.plugins).map(
88
([pluginName, pluginFn]) => ({

src/utils/clean-require.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import tryRequire from 'try-require';
22

33
export default function cleanRequire(
44
path: string,
5-
{ justTry = false, resolve = false }
6-
) {
5+
{ justTry = false, resolve = false }: { justTry?: boolean; resolve?: boolean }
6+
): any {
77
const shouldThrow = !justTry;
88

99
if (require.cache && !!require.cache[path]) {

src/utils/is-template-valid.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ export default function isTemplateValid(
88
return false;
99
}
1010

11-
const api = ['getInfo', 'getCompiledTemplate', 'render'];
11+
const templateApi = ['getInfo', 'getCompiledTemplate', 'render'] as const;
12+
const compilerApi = [...templateApi, 'compile'] as const;
1213

13-
if (options && options.compiler === true) {
14-
api.push('compile');
15-
}
14+
const api = options && options.compiler === true ? compilerApi : templateApi;
1615

1716
return api.every(
1817
method => typeof (template as Template)[method] === 'function'

src/utils/npm-utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const buildInstallCommand = (options: {
2323

2424
const executeCommand = (
2525
options: { command: string[]; path: string; silent?: boolean },
26-
callback: NoParameterCallback<string | number>
26+
callback: NoParameterCallback<string | number | null>
2727
) => {
2828
const cmd = spawn('npm', [...options.command, '--no-package-lock'], {
2929
cwd: options.path,
@@ -44,8 +44,8 @@ const getFullPath = ({
4444

4545
export const init = (
4646
options: { initPath: string; silent: boolean },
47-
callback: NoParameterCallback<string | number>
48-
) => {
47+
callback: NoParameterCallback<string | number | null>
48+
): void => {
4949
const { initPath, silent } = options;
5050
const npminit = ['init', '--yes'];
5151
const cmdOptions = { path: initPath, command: npminit, silent };
@@ -56,7 +56,7 @@ export const init = (
5656
export const installDependencies = (
5757
options: { dependencies: string[]; installPath: string; silent: boolean },
5858
callback: Callback<{ dest: string }, string | number>
59-
) => {
59+
): void => {
6060
const { dependencies, installPath, silent } = options;
6161
const npmi = buildInstallCommand(options);
6262
const cmdOptions = {
@@ -77,7 +77,7 @@ export const installDependencies = (
7777
export const installDependency = (
7878
options: { dependency: string; installPath: string; silent?: boolean },
7979
callback: Callback<{ dest: string }, string | number>
80-
) => {
80+
): void => {
8181
const { dependency, installPath, silent } = options;
8282
const npmi = buildInstallCommand(options);
8383
const cmdOptions = {

src/utils/pad-zero.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
3-
export default function padZero(length: number, data: number) {
1+
export default function padZero(length: number, data: number): string {
42
return Array(length - String(data).length + 1).join('0') + data;
53
}

0 commit comments

Comments
 (0)