Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

feat(template): constrain non-null-parameter with {} #54

Merged
merged 1 commit into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion snapshots/has.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as R_has from '../ramda/dist/src/has';
declare const property: Property;
declare const object: object;

// @dts-jest:pass -> <T>(object: T) => boolean
// @dts-jest:pass -> (object: {}) => boolean
R_has(property);
// @dts-jest:pass -> boolean
R_has(property)(object);
Expand Down
2 changes: 1 addition & 1 deletion snapshots/hasIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as R_hasIn from '../ramda/dist/src/hasIn';
declare const property: Property;
declare const object: object;

// @dts-jest:pass -> <T>(object: T) => boolean
// @dts-jest:pass -> (object: {}) => boolean
R_hasIn(property);
// @dts-jest:pass -> boolean
R_hasIn(property)(object);
Expand Down
4 changes: 2 additions & 2 deletions snapshots/propIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as R_propIs from '../ramda/dist/src/propIs';

declare const object: object;

// @dts-jest:pass -> <U>(object: U) => object is U & Record<"a", Number>
// @dts-jest:pass -> <U extends {}>(object: U) => object is U & Record<"a", Number>
R_propIs(Number)('a');
// @dts-jest:pass -> <U>(object: U) => object is U & Record<"a", Number>
// @dts-jest:pass -> <U extends {}>(object: U) => object is U & Record<"a", Number>
R_propIs(Number, 'a');
// @dts-jest:pass -> boolean
R_propIs(Number)('a')(object);
Expand Down
4 changes: 2 additions & 2 deletions templates/assoc.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Property} from './$types';

export function $extend<K extends string, V, T>(property: K, value: V, object: T): T & Record<K, V>;
export function $general<T>(property: Property, value: any, object: T): T;
export function $extend<K extends string, V, T extends {}>(property: K, value: V, object: T): T & Record<K, V>;
export function $general<T extends {}>(property: Property, value: any, object: T): T;
2 changes: 1 addition & 1 deletion templates/assocPath.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {Path} from './$types';

export function $<T>(path: Path, value: any, object: T): T;
export function $<T extends {}>(path: Path, value: any, object: T): T;
4 changes: 2 additions & 2 deletions templates/dissoc.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Omit} from './$operation';
import {Property} from './$types';

export function $keyof<T, K extends keyof T>(property: K, object: T): Omit<T, K>;
export function $keyof<T extends {}, K extends keyof T>(property: K, object: T): Omit<T, K>;
export function $record<T extends Record<K, any>, K extends string>(property: K, object: T): Omit<T, K>;
export function $general<T>(property: Property, object: T): T;
export function $general<T extends {}>(property: Property, object: T): T;
2 changes: 1 addition & 1 deletion templates/dissocPath.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {DeepPartial} from './$operation';
import {Path} from './$types';

export function $<T>(path: Path, object: T): DeepPartial<T>;
export function $<T extends {}>(path: Path, object: T): DeepPartial<T>;
2 changes: 1 addition & 1 deletion templates/has.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {Property} from './$types';

export function $<T>(property: Property, object: T): boolean;
export function $(property: Property, object: {}): boolean;
2 changes: 1 addition & 1 deletion templates/hasIn.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {Property} from './$types';

export function $<T>(property: Property, object: T): boolean;
export function $(property: Property, object: {}): boolean;
4 changes: 2 additions & 2 deletions templates/pick.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {List, Property} from './$types';

export function $keyof<T, K extends keyof T>(keys: List<K>, object: T): Pick<T, K>;
export function $keyof<T extends {}, K extends keyof T>(keys: List<K>, object: T): Pick<T, K>;
export function $record<T extends Record<K, any>, K extends string>(keys: List<K>, object: T): Pick<T, K>;
export function $general<T>(keys: List<Property>, object: T): Partial<T>;
export function $general<T extends {}>(keys: List<Property>, object: T): Partial<T>;
4 changes: 2 additions & 2 deletions templates/pickAll.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {List, Property} from './$types';

export function $pick<T, K extends keyof T>(keys: List<K>, object: T): Pick<T, K>;
export function $general<T>(keys: List<Property>, object: T): Partial<T>;
export function $pick<T extends {}, K extends keyof T>(keys: List<K>, object: T): Pick<T, K>;
export function $general<T extends {}>(keys: List<Property>, object: T): Partial<T>;
2 changes: 1 addition & 1 deletion templates/pickBy.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import {Dictionary, KeyedObjectMorphism} from './$types';

export function $<T, U extends Dictionary<T>>(fn: KeyedObjectMorphism<T, boolean, keyof U>, object: U): Partial<U>;
export function $<T extends {}, U extends Dictionary<T>>(fn: KeyedObjectMorphism<T, boolean, keyof U>, object: U): Partial<U>;
2 changes: 1 addition & 1 deletion templates/prop.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {List, Property} from './$types';

export function $keyof<T, K extends keyof T>(key: K, object: T): T[K];
export function $keyof<T extends {}, K extends keyof T>(key: K, object: T): T[K];
export function $record<K extends string, T extends Record<K, any>>(key: K, object: T): T[K];
export function $general(key: Property, object: {}): any;
2 changes: 1 addition & 1 deletion templates/propIs.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Constructor, Property} from './$types';

export function $guard<T, U, K extends string>(constructor: Constructor<T>, key: K, object: U): object is U & Record<K, T>;
export function $guard<T, U extends {}, K extends string>(constructor: Constructor<T>, key: K, object: U): object is U & Record<K, T>;
export function $general(constructor: Constructor<any>, key: Property, object: {}): boolean;
2 changes: 1 addition & 1 deletion templates/propOr.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {List, Property} from './$types';

export function $keyof<D, T, K extends keyof T>(defaults: D, key: K, object: T): T[K] | D;
export function $keyof<D, T extends {}, K extends keyof T>(defaults: D, key: K, object: T): T[K] | D;
export function $record<D, K extends string, T extends Record<K, any>>(defaults: D, key: K, object: T): T[K] | D;
export function $general(defaults: any, key: Property, object: {}): any;
2 changes: 1 addition & 1 deletion templates/propSatisfies.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Predicate, Property} from './$types';

export function $keyof<T, K extends keyof T>(fn: Predicate<T[K]>, key: K, object: T): boolean;
export function $keyof<T extends {}, K extends keyof T>(fn: Predicate<T[K]>, key: K, object: T): boolean;
export function $record<K extends string, T extends Record<K, any>>(fn: Predicate<T[K]>, key: K, object: T): boolean;
export function $general<V>(fn: Predicate<V>, key: Property, object: {}): boolean;
2 changes: 1 addition & 1 deletion templates/props.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {List, Property} from './$types';

export function $keyof<T, K extends keyof T>(keys: List<K>, object: T): T[K][];
export function $keyof<T extends {}, K extends keyof T>(keys: List<K>, object: T): T[K][];
export function $record<K extends string, T extends Record<K, any>>(keys: List<K>, object: T): T[K][];
export function $general(keys: Property[], object: {}): any[];
2 changes: 1 addition & 1 deletion templates/values.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export function $<T>(value: T): T[keyof T][];
export function $<T extends {}>(value: T): T[keyof T][];
2 changes: 1 addition & 1 deletion templates/valuesIn.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export function $<T>(value: T): T[keyof T][];
export function $<T extends {}>(value: T): T[keyof T][];
2 changes: 1 addition & 1 deletion tests/__snapshots__/has.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`R_has(property) 1`] = `"<T>(object: T) => boolean"`;
exports[`R_has(property) 1`] = `"(object: {}) => boolean"`;

exports[`R_has(property)(object) 1`] = `"boolean"`;

Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/hasIn.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`R_hasIn(property) 1`] = `"<T>(object: T) => boolean"`;
exports[`R_hasIn(property) 1`] = `"(object: {}) => boolean"`;

exports[`R_hasIn(property)(object) 1`] = `"boolean"`;

Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/propIs.ts.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`R_propIs(Number)('a') 1`] = `"<U>(object: U) => object is U & Record<\\"a\\", Number>"`;
exports[`R_propIs(Number)('a') 1`] = `"<U extends {}>(object: U) => object is U & Record<\\"a\\", Number>"`;

exports[`R_propIs(Number)('a')(object) 1`] = `"boolean"`;

exports[`R_propIs(Number, 'a') 1`] = `"<U>(object: U) => object is U & Record<\\"a\\", Number>"`;
exports[`R_propIs(Number, 'a') 1`] = `"<U extends {}>(object: U) => object is U & Record<\\"a\\", Number>"`;

exports[`R_propIs(Number, 'a', object) 1`] = `"boolean"`;