diff --git a/.prettierignore b/.prettierignore index 460710c..03f7283 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,4 @@ lib coverage package.json -README.md +README.md \ No newline at end of file diff --git a/package.json b/package.json index ca86c75..0a5527f 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "types": "./lib/index.d.ts", "scripts": { "build": "tsc --pretty", - "format": "prettier $([ \"$CI\" == true ] && echo --list-different || echo --write) './**/*.{ts,tsx,js,json,css}'", + "format": + "prettier $([ \"$CI\" == true ] && echo --list-different || echo --write) './**/*.{ts,tsx,js,json,css}'", "test": "jest --no-cache --verbose --coverage", "test:watch": "jest --watch" }, diff --git a/src/index.spec.ts b/src/index.spec.ts index 2306270..e13fa39 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -1,4 +1,4 @@ -import { ofType, unionize } from '.'; +import { ofType, unionize, UnionOf, Unionized } from '.'; describe('merged', () => { const Foo = unionize({ @@ -347,3 +347,14 @@ describe('transform without value prop', () => { expect(Data.transform({ str: strLen })(str)).toEqual(num); }); }); + +describe('type accessors', () => { + describe('unionOf', () => { + it('should be usable', () => { + const T = unionize({ + foo: ofType<{ x: number }>(), + }); + type ActionType = UnionOf; + }); + }); +}); diff --git a/src/index.ts b/src/index.ts index 40e0ff8..4559f5b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,25 @@ -export type Unionized = { +export type Unionized = UnionTypes< + Record, + TaggedRecord +> & + Creators & + UnionExtensions; + +export interface UnionTypes { _Tags: keyof TaggedRecord; _Record: Record; _Union: TaggedRecord[keyof TaggedRecord]; +} +export interface UnionExtensions { is: Predicates; as: Casts; match: Match; transform: Transform; -} & Creators; +} -export type TagsOf> = U['_Tags']; -export type RecordOf> = U['_Record']; -export type UnionOf> = U['_Union']; +export type TagsOf> = U['_Tags']; +export type RecordOf> = U['_Record']; +export type UnionOf> = U['_Union']; export type Creators = { [T in keyof Record]: {} extends UnTagged