diff --git a/README.md b/README.md index aa05c4c..7115bef 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ ![Logo](https://raw.githubusercontent.com/kreuzerk/svg-to-ts/master/assets/logo.png) + [![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors-) + @@ -382,12 +384,12 @@ advantages: ## Can I use the icons to generate a type? -If you have a method that decides which icon should be returned its useful to add a return type. To do so you can take advantage of the `IconNameSubset` helper generated by `svg-to-ts`. +If you have a method that decides which icon should be returned its useful to add a return type. To do so you can take advantage of the name subset helper generated by `svg-to-ts`. The name of the helper will be dynamically generated depending upon the value provided for the `interfaceName` property. An `interfaceName` of `MyIcon` will generate a helper called `MyIconNameSubset` as shown in the following example. ```typescript import {IconNameSubset, myIconSmile, myIconLaugh} from 'my-icon-lib'; -type emojiIcons = IconNameSubset<[typeof myIconSmile, typeof myIconLaugh]>; +type emojiIcons = MyIconNameSubset<[typeof myIconSmile, typeof myIconLaugh]>; // resulting type is equal to type = 'smile' | 'laugh'; @@ -422,6 +424,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d + This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! diff --git a/src/lib/generators/code-snippet-generators.spec.ts b/src/lib/generators/code-snippet-generators.spec.ts index 8c0fda0..9b43b9e 100644 --- a/src/lib/generators/code-snippet-generators.spec.ts +++ b/src/lib/generators/code-snippet-generators.spec.ts @@ -156,7 +156,7 @@ describe('Generators', () => { it('should generate the correct type helper statement', () => { const interfaceName = 'MyIcons'; const expectedStatement = ` - export type IconNameSubset> = T[number]['name']; + export type ${interfaceName}NameSubset> = T[number]['name']; `; const generatedStatement = generateTypeHelper(interfaceName); @@ -170,7 +170,7 @@ describe('Generators', () => { const expectedStatement = ` import {${interfaceName}} from './${iconsFolderName}/${modelFileName}'; - export type IconNameSubset> = T[number]['name']; + export type ${interfaceName}NameSubset> = T[number]['name']; `; const generatedStatement = generateTypeHelperWithImport(interfaceName, iconsFolderName, modelFileName); diff --git a/src/lib/generators/code-snippet-generators.ts b/src/lib/generators/code-snippet-generators.ts index 116b96b..b1c18b6 100644 --- a/src/lib/generators/code-snippet-generators.ts +++ b/src/lib/generators/code-snippet-generators.ts @@ -89,7 +89,7 @@ export const generateVariableName = (prefix: string, filenameWithoutEnding): str }; export const generateTypeHelper = (interfaceName: string): string => ` - export type IconNameSubset> = T[number]['name']; + export type ${interfaceName}NameSubset> = T[number]['name']; `; export const generateTypeHelperWithImport = (