Created
May 10, 2023 17:47
-
-
Save MNBuyskih/03b0550c295254ca99e4f4e4e87c9704 to your computer and use it in GitHub Desktop.
Generate typings for selectors
This file contains 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 fs from "fs"; | |
import * as path from "path"; | |
function main(p: number): string { | |
function create(prefix: string, join = ", "): string { | |
return Array(p) | |
.fill("_") | |
.map((_, i) => `${prefix}${i + 1}`) | |
.join(join); | |
} | |
function create2(): string { | |
return Array(p) | |
.fill("_") | |
.map((_, i) => `ParametricSelector<S${i + 1}, P${i + 1}, R${i + 1}>`) | |
.join(", "); | |
} | |
function create3(): string { | |
return Array(p) | |
.fill("_") | |
.map((_, i) => `res${i + 1}: R${i + 1}`) | |
.join(", "); | |
} | |
const S = create("S"); | |
const P = create("P"); | |
const R = create("R"); | |
const selectors = create2(); | |
const combiner = create3(); | |
return ` | |
// ${p} selectors | |
export function createSelector<${S}, ${P}, ${R}, T>( | |
selectors: [${selectors}], | |
combiner: (${combiner}) => T | |
): OutputParametricSelector<${create("S", " & ")}, ${create("P", " & ")}, T, (${combiner}) => T>;`; | |
} | |
const fileData = [ | |
`/* eslint-disable */ | |
import {ParametricSelector, OutputParametricSelector} from "reselect"; | |
declare module "reselect" {`, | |
]; | |
for (let i = 14; i <= 21; i++) { | |
fileData.push(main(i)); | |
} | |
fileData.push("}"); | |
fs.writeFileSync(path.resolve(__dirname, "reselect.d.ts"), fileData.join("\n")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment