Created
May 8, 2018 11:35
-
-
Save kurogelee/e251cfe7be1fd9104f8d25e9f60d8519 to your computer and use it in GitHub Desktop.
TypeScriptでMap ⇔ Object変換 ref: https://qiita.com/kurogelee/items/8049c51a7c323ce0911e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as _ from "lodash"; | |
function mapToObj<V>(map: Map<number, V>): _.NumericDictionary<V>; | |
function mapToObj<V>(map: Map<string, V>): _.Dictionary<V>; | |
function mapToObj<V>(map: Map<any, V>): _.Dictionary<V> { | |
return _.fromPairs([...map]); | |
} | |
function objToMap<V>(obj: _.NumericDictionary<V>): Map<number, V>; | |
function objToMap<V>(obj: _.Dictionary<V>): Map<string, V>; | |
function objToMap<V>(obj: _.Dictionary<V>): Map<any, V> { | |
return new Map(Object.entries(obj)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment