Skip to content

Commit

Permalink
type given.map
Browse files Browse the repository at this point in the history
  • Loading branch information
MZanggl committed Aug 9, 2020
1 parent 9918c4d commit f400333
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Stringable from "./objects/Stringable"
import Numberable from "./objects/Numberable"
import Mappable from "./objects/Mappable"
import Any from "./objects/Any"
import { MapValue } from './types'

type Callback<T> = (result: T) => any

Expand Down Expand Up @@ -41,7 +42,7 @@ array.macro = (key: string, callback: Function) => (Arrayable.prototype[key] = c
/**
* Create a flooent map. You have access to [everything from the native Map object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map).
*/
const map = <K, V>(value) => new Mappable<K, V>(value)
const map = <K, V>(value: MapValue<K, V>) => new Mappable<K, V>(value)
map.macro = (key: string, callback: Function) => (Mappable.prototype[key] = callback)

/**
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type Constructor<T> = new(...args: any[]) => T

export type CopyFunction<TFn, TR> = TFn extends (...a: infer A) => any ? (...a:A) => TR: never

export type MapValue<K, V> = { [key: string]: V } | Map<K, V> | [K, V][]

0 comments on commit f400333

Please sign in to comment.