Skip to content

Commit 39e537f

Browse files
committed
refactor: fix client ts error
1 parent eab0c04 commit 39e537f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+358
-199
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
}

bin/register.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
*/
55

66
import bcrypt from 'bcryptjs';
7-
import { promisify } from 'util';
87

9-
import User from '../server/models/user';
8+
import User, { UserDocument } from '../server/models/user';
109
import Group from '../server/models/group';
1110

1211
import options from '../utils/commandOptions';
@@ -37,10 +36,11 @@ connectDB()
3736
const defaultGroup = await Group.findOne({ isDefault: true });
3837
if (!defaultGroup) {
3938
exitWithError('默认群组不存在');
39+
return;
4040
}
4141

42-
const salt = await promisify(bcrypt.genSalt)(saltRounds);
43-
const hash = await promisify(bcrypt.hash)(password, salt);
42+
const salt = await bcrypt.genSalt(saltRounds);
43+
const hash = await bcrypt.hash(password, salt);
4444

4545
let newUser = null;
4646
try {
@@ -52,21 +52,24 @@ connectDB()
5252
});
5353
} catch (createError) {
5454
if (createError.name === 'ValidationError') {
55-
return exitWithError('用户名包含不支持的字符或者长度超过限制');
55+
exitWithError('用户名包含不支持的字符或者长度超过限制');
56+
return;
5657
}
5758
console.error(createError);
5859
exitWithError('创建新用户失败');
5960
}
6061

6162
if (!defaultGroup.creator) {
62-
defaultGroup.creator = newUser;
63+
defaultGroup.creator = newUser as UserDocument;
64+
}
65+
if (newUser) {
66+
defaultGroup.members.push(newUser._id);
6367
}
64-
defaultGroup.members.push(newUser);
6568
await defaultGroup.save();
6669

6770
console.log('注册成功');
6871

69-
return process.exit(0);
72+
process.exit(0);
7073
})
7174
.catch((err) => {
7275
console.error('connect database error!');

build/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ process.env.NODE_ENV = 'production';
1414
const spinner = ora('building for production...');
1515
spinner.start();
1616

17-
rm(path.join(config.build.assetsRoot), (err) => {
17+
rm(path.join(config.build.assetsRoot), (err: any) => {
1818
if (err) throw err;
19-
webpack(webpackConfig, (wErr, stats) => {
19+
webpack(webpackConfig, (wErr: any, stats: any) => {
2020
spinner.stop();
2121
if (wErr) throw wErr;
2222
process.stdout.write(`${stats.toString({

build/check-versions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import cp from 'child_process';
66

77
import packageJson from '../package.json';
88

9-
function exec(cmd) {
9+
function exec(cmd: any) {
1010
return cp.execSync(cmd).toString().trim();
1111
}
1212

1313
const versionRequirements = [
1414
{
1515
name: 'node',
16-
currentVersion: semver.clean(process.version),
16+
currentVersion: semver.clean(process.version) as string,
1717
versionRequirement: packageJson.engines.node,
1818
},
1919
{

build/dev-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'eventsource-polyfill';
55
// @ts-ignore
66
import hotClient from 'webpack-hot-middleware/client?noInfo=true&reload=true'; // eslint-disable-line import/no-unresolved
77

8-
hotClient.subscribe((event) => {
8+
hotClient.subscribe((event: any) => {
99
if (event.action === 'reload') {
1010
window.location.reload();
1111
}

build/dev-server.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import opn from 'opn';
55
import path from 'path';
66
import express from 'express';
77
import webpack from 'webpack';
8-
import proxyMiddleware from 'http-proxy-middleware';
98
import webpackDevMiddleware from 'webpack-dev-middleware';
109
import webpackHotMiddleware from 'webpack-hot-middleware';
1110
import connectionHistoryApiFallback from 'connect-history-api-fallback';
@@ -20,7 +19,6 @@ if (!process.env.NODE_ENV) {
2019
const host = process.env.HOST || config.dev.host;
2120
const port = process.env.PORT || config.dev.port;
2221
const autoOpenBrowser = !!config.dev.autoOpenBrowser;
23-
const { proxyTable } = config.dev;
2422

2523
const app = express();
2624
const compiler = webpack(webpackConfig);
@@ -36,22 +34,14 @@ const hotMiddleware = webpackHotMiddleware(compiler, {
3634
});
3735

3836

39-
compiler.plugin('compilation', (compilation) => {
40-
compilation.plugin('html-webpack-plugin-after-emit', (data, cb) => {
37+
compiler.plugin('compilation', (compilation: any) => {
38+
compilation.plugin('html-webpack-plugin-after-emit', (data: any, cb: any) => {
4139
if (cb) {
4240
cb();
4341
}
4442
});
4543
});
4644

47-
Object.keys(proxyTable).forEach((context) => {
48-
let options = proxyTable[context];
49-
if (typeof options === 'string') {
50-
options = { target: options };
51-
}
52-
app.use(proxyMiddleware(options.filter || context, options));
53-
});
54-
5545
app.use(connectionHistoryApiFallback());
5646

5747
app.use(devMiddleware);

build/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import LessPluginAutoPrefix from 'less-plugin-autoprefix';
55
import ExtractTextPlugin from 'extract-text-webpack-plugin';
66
import config from '../config/webpack';
77

8-
export function assetsPath(_path) {
8+
export function assetsPath(_path: any) {
99
return path.posix.join('', _path);
1010
}
1111

build/webpack.base.conf.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import * as utils from './utils';
33
import config from '../config/webpack';
44
import pages from '../config/pages';
55

6-
const entry = {};
6+
const entry: { [key: string]: string } = {};
77
pages.forEach((page) => {
88
entry[page.entry.key] = page.entry.file;
99
});
1010

11-
function resolve(dir) {
11+
function resolve(dir: any) {
1212
return path.join(__dirname, '..', dir);
1313
}
1414

@@ -36,10 +36,7 @@ export default {
3636
{
3737
test: /\.tsx?$/,
3838
exclude: /node_modules/,
39-
use: [
40-
'babel-loader',
41-
'ts-loader',
42-
],
39+
use: ['babel-loader', 'ts-loader'],
4340
},
4441
{
4542
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,

build/webpack.dev.conf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import pages from '../config/pages';
1414
const htmlPlugins = pages.map((page) => new HtmlWebpackPlugin(page));
1515

1616
Object.keys(baseWebpackConfig.entry).forEach((name) => {
17+
// @ts-ignore
1718
baseWebpackConfig.entry[name] = ['react-hot-loader/patch', './build/dev-client'].concat(baseWebpackConfig.entry[name]);
1819
});
1920

build/webpack.prod.conf.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,6 @@ const webpackConfig = merge(baseWebpackConfig, {
3535
rules: utils.getStyleLoaders(),
3636
},
3737
devtool: config.build.productionSourceMap ? '#source-map' : false,
38-
// optimization: {
39-
// splitChunks: {
40-
// cacheGroups: {
41-
// vendor: {
42-
// test: module => /node_modules/.test(module.context),
43-
// chunks: 'initial',
44-
// name: 'vendor',
45-
// enforce: true,
46-
// },
47-
// },
48-
// },
49-
// },
5038
plugins: [
5139
// @ts-ignore
5240
new webpack.DefinePlugin({

0 commit comments

Comments
 (0)