diff --git a/README.md b/README.md index ba3ea3c..17ee176 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,10 @@ npm install @kitbag/mapper ## Basic Setup ```ts -import mapper from '@kitbag/mapper' +import mapper, { createProfile } from '@kitbag/mapper' const profiles = [ - createProfile('number', 'string', (source: number): boolean => source.toString()) + createProfile('number', 'string', (source: number): string => source.toString()), createProfile('number', 'Date', (source: number): Date =>new Date(source)) ] diff --git a/package.json b/package.json index f2e4780..759c8bc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@kitbag/mapper", "private": false, - "version": "0.0.6", + "version": "0.1.0", "description": "A simple and versatile mapping utility for Typescript.", "bugs": { "url": "https://github.com/kitbagjs/mapper/issues" @@ -12,6 +12,7 @@ "types": "./dist/src/index.d.ts", "exports": { ".": { + "types": "./dist/src/index.d.ts", "import": "./dist/mapper.mjs", "require": "./dist/mapper.umd.cjs" } diff --git a/src/types/mapper.ts b/src/types/mapper.ts index b4786f4..1fb5786 100644 --- a/src/types/mapper.ts +++ b/src/types/mapper.ts @@ -10,8 +10,10 @@ type ProfileIndex = { } } +/** Extracts the source type from a profile. `unknown` for the destination parameter matches any profile regardless of its destination type. */ type ProfileSource = TProfile extends Profile ? TSource : never +/** Extracts the destination type from a profile. `never` for the source parameter exploits contravariance — any concrete source type satisfies `never extends TSource` in the function position, so the match is unconditional. */ type ProfileDestination = TProfile extends Profile ? TDestination : never export type Mapper = { diff --git a/src/types/profile.ts b/src/types/profile.ts index 900b376..1217a7e 100644 --- a/src/types/profile.ts +++ b/src/types/profile.ts @@ -10,13 +10,5 @@ export type ProfileKey = `${T['sourceKey']}-${T['destinationK // eslint-disable-next-line @typescript-eslint/no-explicit-any export type ExtractSourceKeys = TProfile extends Profile ? TSourceKey : never -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export type ExtractSources> = TProfile extends Profile ? TSource : never - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export type ExtractDestinationKeys> = TProfile extends Profile ? TDestinationKey : never - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export type ExtractDestinations, TDestinationKey extends ExtractDestinationKeys> = TProfile extends Profile ? TDestination : never export type Profiles = readonly Profile[]