Skip to content

Commit

Permalink
Add return type
Browse files Browse the repository at this point in the history
  • Loading branch information
fwh1990 committed May 20, 2019
1 parent ead9ead commit f5a6199
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "antd-form-rules",
"version": "1.1.0",
"version": "1.1.1",
"main": "index.js",
"types": "index.d.ts",
"repository": "[email protected]:fwh1990/antd-form-rules.git",
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class FormRules {
return new FormRules(fieldLocalName);
}

private static formatMessageByLimit(min?: number, max?: number, type: string = '', unit: string = '') {
private static formatMessageByLimit(min?: number, max?: number, type: string = '', unit: string = ''): string {
const existMin = typeof min === 'number';
const existMax = typeof max === 'number';
let message: string;
Expand Down Expand Up @@ -132,7 +132,7 @@ export class FormRules {
return this;
}

public integer(min?: number, max?: number, message = '') {
public integer(min?: number, max?: number, message = ''): FormRules {
message = message || FormRules.formatMessageByLimit(min, max, '整数', '值');

this.rules.push({
Expand All @@ -146,7 +146,7 @@ export class FormRules {
return this;
}

public email(message = ':name必须是个邮箱号') {
public email(message = ':name必须是个邮箱号'): FormRules {
this.rules.push({
type: FormRuleType.email,
message: message.replace(':name', this.name),
Expand All @@ -155,7 +155,7 @@ export class FormRules {
return this;
}

public match(pattern: RegExp, message = ':name不符合匹配标准') {
public match(pattern: RegExp, message = ':name不符合匹配标准'): FormRules {
this.rules.push({
type: FormRuleType.string,
pattern,
Expand All @@ -165,7 +165,7 @@ export class FormRules {
return this;
}

public url(message = ':name不符合url规则') {
public url(message = ':name不符合url规则'): FormRules {
this.rules.push({
type: FormRuleType.url,
message: message.replace(':name', this.name),
Expand All @@ -174,7 +174,7 @@ export class FormRules {
return this;
}

public callback<T extends Error>(func: (value: any, field: string) => T | T[] | void) {
public callback<T extends Error>(func: (value: any, field: string) => T | T[] | void): FormRules {
this.rules.push({
validator: (rule, value, callback) => {
const errors: T | T[] | void = func(value, rule.field);
Expand All @@ -186,7 +186,7 @@ export class FormRules {
return this;
}

public identityCard(message = ':name不是有效的身份证') {
public identityCard(message = ':name不是有效的身份证'): FormRules {
return this.match(/^(\d{18}|\d{17}[xX])$/, message);
}

Expand Down

0 comments on commit f5a6199

Please sign in to comment.