Skip to content

Commit 7f3b2d5

Browse files
authored
Merge pull request #31 from Coder-Spirit/issue-12
Improve tag types interaction
2 parents f5becf6 + 4e404ba commit 7f3b2d5

36 files changed

+364
-117
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Dependencies, Caches & Artifacts
22
dist/
33
node_modules/
4+
tsconfig.tsbuildinfo

nominal/.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ src/
77
.npmignore
88
jest.config.js
99
package-lock.json
10-
README.md
1110
tsconfig.base.json
1211
tsconfig.esm.json
1312
tsconfig.json
13+
tsconfig.tsbuildinfo

nominal/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ npm install @coderspirit/nominal
4040
yarn add @coderspirit/nominal
4141
```
4242

43-
### Deno
43+
### [Deno](https://deno.land/)
4444

4545
`Nominal` is served through different CDNs
4646
```typescript

nominal/deno/GenericTainted.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { SimpleTypeTag } from './internal/UtilTypes.ts';
2-
import { TagsMarker } from './internal/TagsMarker.ts';
1+
import { TagWrapper } from './internal/TagUtils.ts';
2+
import { TagsMarker } from './internal/Markers.ts';
33
import { WithTag } from './WithTag.ts';
44

55
export type GenericTainted<
@@ -17,15 +17,15 @@ export type GenericTainted<
1717
| string
1818
| symbol
1919
| Date
20-
? BaseType0 & TagsMarker<BaseType0, TypeTags0 & SimpleTypeTag<TaintTag>>
20+
? BaseType0 & TagsMarker<BaseType0, TypeTags0 & TagWrapper<TaintTag>>
2121
: { [P in keyof BaseType0]: GenericTainted<BaseType0[P], TaintTag> } &
2222
TagsMarker<
2323
{
2424
[P in keyof BaseType0]: GenericTainted<BaseType0[P], TaintTag>
2525
},
26-
TypeTags0 & SimpleTypeTag<TaintTag>
26+
TypeTags0 & TagWrapper<TaintTag>
2727
>
28-
: BaseType0 & TagsMarker<BaseType0, TypeTags0 & SimpleTypeTag<TaintTag>>
28+
: BaseType0 & TagsMarker<BaseType0, TypeTags0 & TagWrapper<TaintTag>>
2929
: // eslint-disable-next-line @typescript-eslint/no-unused-vars
3030
BaseType extends Partial<Record<infer _K, infer _V>>
3131
? BaseType extends

nominal/deno/GenericUntainted.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GenericTainted } from './GenericTainted.ts';
22
import { NegateTag } from './NegateTag.ts';
3-
import { TagsMarker } from './internal/TagsMarker.ts';
3+
import { TagsMarker } from './internal/Markers.ts';
44

55
export type GenericUntainted<
66
BaseType,

nominal/deno/NegateTag.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1-
import { SimpleTypeNegation, SimpleTypeTag } from './internal/UtilTypes.ts';
2-
import { TagsMarker } from './internal/TagsMarker.ts';
1+
import { NegatedTagWrapper, TagWrapper } from './internal/TagUtils.ts';
2+
import { OptionalTagsMarker, TagsMarker } from './internal/Markers.ts';
33

44
export type NegateTag<
55
BaseType,
66
TypeTag extends string | symbol
77
> = BaseType extends TagsMarker<infer BaseType0, infer TypeTags0>
88
? BaseType0 &
9-
(TagsMarker<BaseType0, SimpleTypeTag<TypeTag>> extends TagsMarker<
9+
(TagsMarker<BaseType0, TagWrapper<TypeTag>> extends TagsMarker<
1010
BaseType0,
1111
TypeTags0
1212
>
1313
? Partial<
1414
TagsMarker<
1515
BaseType0,
16-
TypeTags0 extends SimpleTypeTag<TypeTag> & infer RestTypeTags
17-
? RestTypeTags & SimpleTypeNegation<TypeTag>
18-
: Omit<TypeTags0, TypeTag> & SimpleTypeNegation<TypeTag>
16+
TypeTags0 extends TagWrapper<TypeTag> & infer RestTypeTags
17+
? RestTypeTags & NegatedTagWrapper<TypeTag>
18+
: Omit<TypeTags0, TypeTag> & NegatedTagWrapper<TypeTag>
1919
>
2020
>
2121
: TagsMarker<
2222
BaseType0,
23-
TypeTags0 extends SimpleTypeTag<TypeTag> & infer RestTypeTags
24-
? RestTypeTags & SimpleTypeNegation<TypeTag>
25-
: Omit<TypeTags0, TypeTag> & SimpleTypeNegation<TypeTag>
23+
TypeTags0 extends TagWrapper<TypeTag> & infer RestTypeTags
24+
? RestTypeTags & NegatedTagWrapper<TypeTag>
25+
: Omit<TypeTags0, TypeTag> & NegatedTagWrapper<TypeTag>
2626
>)
27-
: BaseType & Partial<TagsMarker<BaseType, SimpleTypeNegation<TypeTag>>>
27+
: BaseType extends OptionalTagsMarker<infer BaseType0, infer TypeTags0>
28+
? BaseType0 &
29+
Partial<
30+
TagsMarker<
31+
BaseType0,
32+
TypeTags0 extends TagWrapper<TypeTag> & infer RestTypeTags
33+
? RestTypeTags & NegatedTagWrapper<TypeTag>
34+
: Omit<TypeTags0, TypeTag> & NegatedTagWrapper<TypeTag>
35+
>
36+
>
37+
: BaseType & Partial<TagsMarker<BaseType, NegatedTagWrapper<TypeTag>>>

nominal/deno/WithTag.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
import { SimpleTypeTag } from './internal/UtilTypes.ts';
2-
import { TagsMarker } from './internal/TagsMarker.ts';
1+
import { ExtendedTagWrapper, NegatedTagWrapper, TagWrapper } from './internal/TagUtils.ts';
2+
import { OptionalTagsMarker, TagsMarker } from './internal/Markers.ts';
33

44
export type WithTag<
55
BaseType,
66
TypeTag extends string | symbol
77
> = BaseType extends TagsMarker<infer BaseType0, infer TypeTags0>
8-
? BaseType0 & TagsMarker<BaseType0, TypeTags0 & SimpleTypeTag<TypeTag>>
9-
: BaseType & TagsMarker<BaseType, SimpleTypeTag<TypeTag>>
8+
? BaseType0 &
9+
TagsMarker<
10+
BaseType0,
11+
(TypeTags0 extends ExtendedTagWrapper<TypeTag> & infer TypeTags1
12+
? TypeTags1
13+
: TypeTags0) &
14+
TagWrapper<TypeTag>
15+
>
16+
: BaseType extends OptionalTagsMarker<infer BaseType0, infer TypeTags0>
17+
? BaseType0 &
18+
TagsMarker<
19+
BaseType0,
20+
TypeTags0 extends NegatedTagWrapper<TypeTag> & infer TypeTags1
21+
? TypeTags1 & TagWrapper<TypeTag>
22+
: TagWrapper<TypeTag>
23+
>
24+
: BaseType & TagsMarker<BaseType, TagWrapper<TypeTag>>

nominal/deno/WithTags.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { CompoundTypeTags } from './internal/UtilTypes.ts';
2-
import { TagsMarker } from './internal/TagsMarker.ts';
1+
import { ManyTagsWrapper, MergeTags } from './internal/TagUtils.ts';
2+
import { OptionalTagsMarker, TagsMarker } from './internal/Markers.ts';
33

44
export type WithTags<
55
BaseType,
66
TypeTags extends (string | symbol)[]
77
> = BaseType extends TagsMarker<infer BaseType0, infer TypeTags0>
8-
? BaseType0 & TagsMarker<BaseType0, TypeTags0 & CompoundTypeTags<TypeTags>>
9-
: BaseType & TagsMarker<BaseType, CompoundTypeTags<TypeTags>>
8+
? BaseType0 & TagsMarker<BaseType0, MergeTags<TypeTags0, TypeTags>>
9+
: BaseType extends OptionalTagsMarker<infer BaseType0, infer TypeTags0>
10+
? BaseType0 & TagsMarker<BaseType0, MergeTags<TypeTags0, TypeTags>>
11+
: BaseType & TagsMarker<BaseType, ManyTagsWrapper<TypeTags>>

nominal/deno/WithoutTag.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { SimpleTypeTag } from './internal/UtilTypes.ts';
2-
import { TagsMarker } from './internal/TagsMarker.ts';
1+
import { TagWrapper } from './internal/TagUtils.ts';
2+
import { TagsMarker } from './internal/Markers.ts';
33

44
export type WithoutTag<
55
BaseType,
66
TypeTag extends string | symbol
77
> = BaseType extends TagsMarker<infer BaseType0, infer TypeTags0>
8-
? TagsMarker<BaseType0, SimpleTypeTag<TypeTag>> extends TagsMarker<
8+
? TagsMarker<BaseType0, TagWrapper<TypeTag>> extends TagsMarker<
99
BaseType0,
1010
TypeTags0
1111
>
1212
? BaseType0
1313
: BaseType0 &
1414
TagsMarker<
1515
BaseType0,
16-
TypeTags0 extends SimpleTypeTag<TypeTag> & infer RestTypeTags
16+
TypeTags0 extends TagWrapper<TypeTag> & infer RestTypeTags
1717
? RestTypeTags
1818
: Omit<TypeTags0, TypeTag>
1919
>

nominal/deno/WithoutTags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TagsMarker } from './internal/TagsMarker.ts';
1+
import { TagsMarker } from './internal/Markers.ts';
22
import { WithoutTag } from './WithoutTag.ts';
33

44
export type WithoutTags<

0 commit comments

Comments
 (0)