Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

optional-chain

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

optional-chain - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

example/dist/example/index.d.ts

8

dist/index.d.ts
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxJQUFZLFVBR1g7QUFIRCxXQUFZLFVBQVU7SUFDcEIsMkNBQUksQ0FBQTtJQUNKLDJDQUFJLENBQUE7QUFDTixDQUFDLEVBSFcsVUFBVSxHQUFWLGtCQUFVLEtBQVYsa0JBQVUsUUFHckI7QUFFWSxRQUFBLFFBQVEsR0FBRyxVQUFJLEtBQVE7SUFDbEMsT0FBTyxJQUFJLE1BQU0sQ0FBQyxLQUFLLENBQUMsQ0FBQztBQUMzQixDQUFDLENBQUM7QUFFRjtJQUdFLGdCQUFZLEtBQVE7UUFDbEIsSUFBSSxDQUFDLEtBQUssR0FBRyxLQUFLLENBQUM7UUFDbkIsSUFBSSxJQU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LENBQUMsU0FBZ0IsQ0FBQyxDQUFDO0tBQ3JDO0lBQ0QsT0FBTyxJQUFJLE1BQU0sQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUM7QUFDdkMsQ0FBQyxDQUFDIn0=
{
"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>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc