Advertisement
jcho0k

groupStyles.ts

Jul 3rd, 2020
4,635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type MergedSheet<T> = { [P in keyof T]?: T[P][] }
  2.  
  3. export function groupStyles<T>(
  4.   sheets: Array<T>
  5. ): MergedSheet<T> {
  6.   const merged: MergedSheet<T> = {}
  7.   for (const sheet of sheets) {
  8.     for (const ele in sheet) {
  9.       if (merged[ele]) {
  10.         merged[ele] = merged[ele] || []
  11.  
  12.         merged[ele].push(sheet[ele])
  13.         //          ^^^^
  14.         // [tsserver 2339] [E] Property 'push' does not exist on type 'MergedSheet<T>[Extract<keyof T, string>]'.
  15.  
  16.       } else {
  17.         merged[ele] = [sheet[ele]]
  18.       }
  19.     }
  20.   }
  21.   return merged
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement