Skip to content

Commit

Permalink
Merge pull request #19 from wz2cool/15-getordefault-增加多值判断最后一个是默认值
Browse files Browse the repository at this point in the history
fix nonable issue
  • Loading branch information
wz2cool committed May 19, 2024
2 parents 5c63db8 + 5b04805 commit f211a77
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-commons",
"version": "1.0.37",
"version": "1.0.38",
"description": "common methods for typescript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -77,4 +77,4 @@
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0"
}
}
}
12 changes: 6 additions & 6 deletions src/utils/object.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,16 @@ export class ObjectUtils {
* @example ObjectUtils.getOrDefault(number | null>)(null, null, null) = null
* @example ObjectUtils.getOrDefault(number | null>)(null, null, null, 3) = "3"
*/
public static getOrDefault<T>(value1: T, defaultValue: T): T;
public static getOrDefault<T>(value1: T, value2: T, defaultValue: T): T;
public static getOrDefault<T>(value1: T, value2: T, value3: T, defaultValue: T): T;
public static getOrDefault<T>(value1: T, defaultValue: NonNullable<T>): NonNullable<T>;
public static getOrDefault<T>(value1: T, value2: T, defaultValue: NonNullable<T>): NonNullable<T>;
public static getOrDefault<T>(value1: T, value2: T, value3: T, defaultValue: NonNullable<T>): NonNullable<T>;
public static getOrDefault<T>(
value1: T,
value2: T,
value3: T,
defaultValue: T
): T
public static getOrDefault<T>(value1: T, value2?: T, value3?: T, defaultValue?: T): T {
defaultValue: NonNullable<T>
): NonNullable<T>
public static getOrDefault<T>(value1: T, value2?: T, value3?: T, defaultValue?: NonNullable<T>): NonNullable<T> {
if (!ObjectUtils.isNullOrUndefined(value1)) {
return value1 as NonNullable<T>;
}
Expand Down
4 changes: 2 additions & 2 deletions test/utils/object.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ describe(".ObjectUtils", () => {
it("should return 'defaultValue', if all values is null", () => {
const value1: string | undefined = undefined;
const value2: string | undefined = undefined;
const result = ObjectUtils.getOrDefault(value1, value2, "defaultValue");
const result = ObjectUtils.getOrDefault<string | undefined>(value1, value2, "defaultValue");
expect("defaultValue").to.be.eq(result);
})

it("should return 'defaultValue', if all values is null", () => {
const value1: string | undefined = undefined;
const value2: string | undefined = undefined;
const value3: string | undefined = undefined;
const result = ObjectUtils.getOrDefault(value1, value2, value3, "defaultValue");
const result = ObjectUtils.getOrDefault<string | undefined>(value1, value2, value3, "defaultValue");
expect("defaultValue").to.be.eq(result);
})

Expand Down

0 comments on commit f211a77

Please sign in to comment.