optional-chain
Advanced tools
Comparing version 0.1.0 to 0.1.1
export declare enum OptionType { | ||
None = 0, | ||
Some = 1, | ||
Some = 1 | ||
} | ||
export declare const optional: <T>(value: T) => Option<T>; | ||
export declare type Diff<T, U> = T extends U ? never : T; | ||
export declare type NonNullable<T> = Diff<T, null | undefined>; | ||
export declare class Option<T> { | ||
@@ -10,6 +12,6 @@ readonly value: T; | ||
constructor(value: T); | ||
k<K extends keyof T>(key: K): Option<T[K]>; | ||
k<K extends keyof T>(key: K): Option<NonNullable<T[K]>>; | ||
i: T extends Array<infer I> ? (index: number) => Option<I> : Option<undefined>; | ||
get(): T; | ||
match({some, none}: { | ||
match({ some, none }: { | ||
some: (v: T) => any; | ||
@@ -16,0 +18,0 @@ none: (v: T) => any; |
@@ -46,2 +46,2 @@ "use strict"; | ||
}; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxJQUFZLFVBR1g7QUFIRCxXQUFZLFVBQVU7SUFDcEIsMkNBQUksQ0FBQTtJQUNKLDJDQUFJLENBQUE7QUFDTixDQUFDLEVBSFcsVUFBVSxHQUFWLGtCQUFVLEtBQVYsa0JBQVUsUUFHckI7QUFFWSxRQUFBLFFBQVEsR0FBRyxVQUFJLEtBQVE7SUFDbEMsT0FBTyxJQUFJLE1BQU0sQ0FBQyxLQUFLLENBQUMsQ0FBQztBQUMzQixDQUFDLENBQUM7QUFFRjtJQUdFLGdCQUFZLEtBQVE7UUFDbEIsSUFBSSxDQUFDLEtBQUssR0FBRyxLQUFLLENBQUM7UUFDbkIsSUFBSSxJQUFJLENBQUMsS0FBSyxLQUFLLFNBQVMsSUFBSSxJQUFJLENBQUMsS0FBSyxLQUFLLElBQUksRUFBRTtZQUNuRCxJQUFJLENBQUMsSUFBSS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QUFDLEtBQUssQ0FBQyxDQUFDLENBQUM7QUFDdkMsQ0FBQyxDQUFDIn0= |
{ | ||
"name": "optional-chain", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "", | ||
@@ -28,3 +28,3 @@ "main": "dist/index.js", | ||
"ts-jest": "^22.4.2", | ||
"typescript": "^2.8.1" | ||
"typescript": "^2.9.2" | ||
}, | ||
@@ -31,0 +31,0 @@ "jest": { |
@@ -10,2 +10,5 @@ export enum OptionType { | ||
export type Diff<T, U> = T extends U ? never : T; | ||
export type NonNullable<T> = Diff<T, null | undefined>; | ||
export class Option<T> { | ||
@@ -22,8 +25,9 @@ readonly value: T; | ||
} | ||
public k<K extends keyof T>(key: K): Option<T[K]> { | ||
public k<K extends keyof T>(key: K): Option<NonNullable<T[K]>> { | ||
if (this.type === OptionType.None) { | ||
return new Option(undefined as any); | ||
return new Option(undefined) as any; | ||
} | ||
return new Option(this.value[key]); | ||
return new Option(this.value[key]) as any; | ||
} | ||
public i: T extends Array<infer I> | ||
@@ -30,0 +34,0 @@ ? (index: number) => Option<I> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22452
20
435