Skip to content

Commit 4fb6032

Browse files
committed
add object types to _index reference
1 parent 34db3d4 commit 4fb6032

File tree

11 files changed

+384
-78
lines changed

11 files changed

+384
-78
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
tests/
33
tests_origin/
4-
.vscode/
4+
.vscode/
5+
test-utility-types/

CHANGELOG.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
2.0.0 - object arg for KeysArray instead of union. revert to KeysArray. replace KeysArray to KeysAsTuple. Update index.ts. Update index.ts. Update $research.ts. Update $research.ts. Update $research.ts. Update $research.ts. Update $research.ts. Update $research.ts. Update $research.ts. rename required to nonnullable. window isTrust guard. drop node as default target inside onevents. G generic arg for the UIEvent for forcing spcifying targe type . add setPrototypeOf. IsUnion & UnionToIntersection. currentTarget fix win types. fix utility desc. drop keys. remove rollup config. Filter & KeysMatching utils. fix merge type args. fix paths in settings json. peerDependencies up. drop hooks. check hook. dom tests attached. utility types renaming.
2+
34db3d4 object arg for KeysArray instead of union
3+
0289818 -
4+
ff2317b -
5+
d954453 revert to KeysArray
6+
9d97320 Merge branch 'master' of github.com:Sanshain/types-spring
7+
40bc227 -
8+
ce33cd3 replace KeysArray to KeysAsTuple
9+
784a9c4 Update index.ts
10+
073f6fa Update index.ts
11+
ee8eec4 Update README.md
12+
7e4315d Update README.md
13+
2fcd201 Update $research.ts
14+
a0b66fa Update $research.ts
15+
033ad43 Update $research.ts
16+
8853355 Update $research.ts
17+
61b1e92 Update $research.ts
18+
6bbe18b Update $research.ts
19+
b665683 Update $research.ts
20+
2724d82 Update README.md
21+
67f7a90 OptionalExceptOne
22+
2e99c62 Update README.md
23+
2c45b07 changelog
24+
c6c7493 Update README.md
25+
2188a94 update utils readme
26+
455aa0e Merge branch 'master' of github.com:Sanshain/types-spring
27+
f012fd7 rename required to nonnullable
28+
ffff0d8 Update README.md
29+
d54f683 Update README.md
30+
f6dcc09 Update README.md
31+
6f9c5f7 Update README.md
32+
e33cf4e Update README.md
33+
ec90e8e Update README.md
34+
f19baf6 Update README.md mnu as table
35+
9a41907 Update README.md - top table of content
36+
7c57574 Update README.md
37+
af6d259 window isTrust guard
38+
24440d5 ver up
39+
d0323fc Merge branch 'master' of github.com:Sanshain/types-spring
40+
cf82dc4 Update README.md
41+
843c50f drop node as default target inside onevents
42+
86226cf Merge branch 'master' of github.com:Sanshain/types-spring
43+
fc32ba5 G generic arg for the UIEvent for forcing spcifying targe type (tested for Window)
44+
2b9b3a2 Update README.md
45+
84b94e0 add setPrototypeOf
46+
1f5d5bd Merge branch 'master' of github.com:Sanshain/types-spring
47+
33af277 IsUnion & UnionToIntersection
48+
5a0b60b Update README.md
49+
24fa9c2 Update README.md
50+
f1d4dc5 Update README.md
51+
d41f345 Update README.md
52+
6f2f5c2 1.0.8
53+
a3d58a7 Merge branch 'master' of github.com:Sanshain/types-spring
54+
618e3d2 currentTarget fix win types
55+
d77f2b0 Update README.md
56+
9b7291f Update README.md
57+
98d6f2c Merge branch 'master' of github.com:Sanshain/types-spring
58+
c3a47ae fix utility desc
59+
9e8d269 Update README.md
60+
f5a4f8d Update README.md
61+
e706722 Update README.md
62+
d337668 Update README.md
63+
d45cda9 Update README.md
64+
29cd587 Update README.md
65+
eaec745 Merge branch 'master' of github.com:Sanshain/types-spring
66+
583031b Update README.md
67+
c235edd Update README.md
68+
61b2da4 Update README.md
69+
ec31042 Update README.md
70+
e24da06 Update README.md
71+
3a69b38 Update README.md
72+
3c62d67 Update README.md
73+
0e453cf types-fest
74+
6f61746 drop keys
75+
035897b remove rollup config
76+
16d32fc Update README.md
77+
43f4f67 Update README.md
78+
bc6d7cc Update README.md
79+
d187365 Update README.md
80+
9a6ab8c Update README.md
81+
70e5680 Update README.md
82+
198e260 Update README.md
83+
57e584d Update README.md
84+
e3d76e8 Update README.md
85+
f80a72e Update README.md
86+
a067528 Update README => Object.keys
87+
3e42fa5 Update README.md
88+
a7d2fdd Update README.md
89+
0049575 addEventListener
90+
686f243 Merge branch 'master' of github.com:Sanshain/types-spring
91+
7c9ecd0 Filter & KeysMatching utils
92+
0049ca4 Update README.md
93+
b5b4650 Update README.md
94+
0acbc4e Update README.md
95+
9eb1495 Update README.md
96+
75ad0d7 Update README.md
97+
b30db68 Update README.md
98+
9844aab fix merge type args
99+
73dfd94 fix paths in settings json
100+
c77c0e2 peerDependencies up
101+
38513e2 Merge branch 'master' of github.com:Sanshain/types-spring
102+
9c9078b 1.0.3 -- fix npmignore
103+
65d0df4 npmignore
104+
21538fe Update README.md
105+
a4d1269 Update README.md
106+
a96127e Update README.md
107+
bdf0d3f Update README.md
108+
15ee410 Update README.md
109+
f0231fb Update README.md
110+
b2f78fd Update README.md
111+
b9e945b Update README.md
112+
eb216af Update README.md
113+
c1421e3 Update README.md
114+
82fe5db menu
115+
9bb2695 Merge branch 'master' of github.com:Sanshain/types-spring
116+
196f3cc drop hooks
117+
5416e86 check hook
118+
d46be15 tests
119+
05b739b Update README.md
120+
5f6a146 Update README.md
121+
90ddb2c Update README.md
122+
3df3a47 Update README.md
123+
649f5d1 dom tests attached
124+
0d86d30 Update README.md
125+
84d3957 Update README.md
126+
29f0cff Update README.md
127+
582721d Merge branch 'master' of github.com:Sanshain/types-spring
128+
4d4c1e8 utility types renaming
129+
4d134df Update README.md
130+
393fe1a Update README.md
131+
e687669 Update README.md
132+
1f305f3 Update README.md
133+
35f70a2 Update README.md
134+
3e73581 Update README.md
135+
61595fe Update README.md
136+
c498f34 Create README.md
137+
d2afcea Update README.md
138+
a42248f Update README.md
139+
35796c7 readme
140+
15f34f3 license
141+
56fc101 restruct
142+
cfdea16 initial

package-lock.json

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
},
1414
"scripts": {
1515
"test": "tsc --noEmit",
16-
"log": "node ./dev-tools/changelog.js",
16+
"$log": "node ./dev-tools/changelog.js",
17+
"changelog": "changelog --titled",
1718
"hooks": "simple-git-hooks"
1819
},
1920
"simple-git-hooks": {
@@ -35,7 +36,8 @@
3536
},
3637
"devDependencies": {
3738
"@types/node": "^20.2.5",
39+
"npm-changelog": "^1.0.21",
3840
"simple-git-hooks": "^2.8.1",
3941
"typescript": "^5.0.4"
4042
}
41-
}
43+
}

sources/document/querySelector.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,26 @@ interface ParentNode {
2424
/** Returns the first element that is a descendant of node that matches selectors. */
2525
querySelector<K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null;
2626
querySelector<K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K] | null;
27-
querySelector<K extends keyof MathMLElementTagNameMap>(selectors: K): MathMLElementTagNameMap[K] | null;
2827
// /** @deprecated */
2928
querySelector<K extends keyof HTMLElementDeprecatedTagNameMap>(selectors: K): HTMLElementDeprecatedTagNameMap[K] | null;
3029
querySelector<S extends string>(selector: S): HTMLSelector<S> | null
3130

3231
/** Returns all element descendants of node that match selectors. */
3332

3433
querySelectorAll<K extends keyof HTMLElementTagNameMap>(selectors: K): NodeListOf<HTMLElementTagNameMap[K]>;
35-
querySelectorAll<K extends keyof SVGElementTagNameMap>(selectors: K): NodeListOf<SVGElementTagNameMap[K]>;
36-
querySelectorAll<K extends keyof MathMLElementTagNameMap>(selectors: K): NodeListOf<MathMLElementTagNameMap[K]>;
34+
querySelectorAll<K extends keyof SVGElementTagNameMap>(selectors: K): NodeListOf<SVGElementTagNameMap[K]>;
3735
/** @deprecated */
3836
querySelectorAll<K extends keyof HTMLElementDeprecatedTagNameMap>(selectors: K): NodeListOf<HTMLElementDeprecatedTagNameMap[K]>;
3937
querySelectorAll<S extends string>(selector: S): NodeListOf<HTMLSelector<S>> | null;
4038

4139
// querySelector<E extends Element = Element>(selectors: string): E;
4240
// querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
41+
42+
43+
/// drop because of ^5.0.0 required:
44+
45+
// querySelector<K extends keyof MathMLElementTagNameMap>(selectors: K): MathMLElementTagNameMap[K] | null;
46+
// querySelectorAll<K extends keyof MathMLElementTagNameMap>(selectors: K): NodeListOf<MathMLElementTagNameMap[K]>;
4347
}
4448

4549

sources/ecmascript/object/_index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
//<reference path='./objectAssign.d.ts' />
1+
///<reference path='./objectAssign.d.ts' />
2+
///<reference path='./defineProperty.d.ts' />
3+
///<reference path='./defineProperties.ts' />
4+
///<reference path='./create.ts' />
5+
///<reference path='./setPrototypeOf.ts' />
26
//<reference path='./objectKeys.d.ts' />

sources/utils/$research.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,50 @@
1515

1616
type F = ExcludeFrom<Array<string | number>, number>
1717
}
18+
19+
20+
{
21+
/// Optional Tuple
22+
23+
type RemoveFirstFromTuple<T extends any[]> =
24+
T['length'] extends 0 ? undefined :
25+
(((...b: T) => void) extends (a: any, ...b: infer I) => void ? I : [])
26+
27+
type Tail<T extends any[]> = T extends [infer A, ...infer R] ? R : never;
28+
29+
30+
type OptionalTuple<T extends any[], A extends unknown[] = [], R extends unknown[] = never> = T['length'] extends 0
31+
? R | A
32+
: OptionalTuple<RemoveFirstFromTuple<T> extends any[] ? RemoveFirstFromTuple<T> : [], [...A, T[0]], A['length'] extends 0 ? never : (A | R)>
33+
34+
{
35+
type A = [1, 2, 3]
36+
type POP = OptionalTuple<A>
37+
let t1: POP = [1]
38+
let t2: POP = [1, 2]
39+
let t3: POP = [1, 2, 3]
40+
}
41+
42+
// declined now because the same behavior could got in fact OUT OF THE BOX (!) by one line:
43+
44+
{
45+
type F = (a: 1, b?: 2, c?: 3) => void
46+
type POP1 = Parameters<F>
47+
let t1: POP1 = [1]
48+
let t2: POP1 = [1, 2]
49+
let t3: POP1 = [1, 2, 3]
50+
51+
// type OPtionalTuple
52+
}
53+
54+
// or
55+
56+
{
57+
type A = [a: 1, b?: 2, c?: 3]
58+
}
59+
60+
/**
61+
* Thus, the benefit of this type is probably only to make a non-optional tuple optional, since there may be difficulties with this.
62+
* But this is such a rare case that I doubt it will be much in demand from the community. Therefore, I do not see it useful to add it to the package (at least for now)
63+
*/
64+
}

sources/utils/index.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type _KeysArray<Dict extends object, Result extends PropertyKey[] = []> = {
33
[Key in keyof Dict]: Exclude<keyof Dict, Key> extends never ? [...Result, Key] : _KeysArray<Omit<Dict, Key>, [...Result, Key]>;
44
}[keyof Dict];
55

6-
type KeysArray__Error = 'Object with too much (more than six) fields passed to KeysArray type'
6+
type KeysArray__Error<L extends number, N extends number> = `Object with too much (${N}) fields amount (expected less than ${L}) passed to KeysArray type`
77
/**
88
* @cat Array
99
* @param { a | b | c | ... } FieldKeys
@@ -13,7 +13,7 @@ type KeysArray__Error = 'Object with too much (more than six) fields passed to K
1313
* @cat Object
1414
* @example KeysArray< {a,b,c} > = ['a', 'b', 'c']
1515
*/
16-
export type KeysArray<Dict extends object> = ObjectLength<Dict> extends Enumerate<7> ? _KeysArray<Dict> : KeysArray__Error
16+
export type KeysArray<Dict extends object, L extends Enumerate<8> = 7> = ObjectLength<Dict> extends Enumerate<L> ? _KeysArray<Dict> : KeysArray__Error<L, ObjectLength<Dict>>
1717

1818

1919
/**
@@ -276,9 +276,9 @@ export type MapArray<T extends Record<F, unknown>[] | ReadonlyArray<Record<F, un
276276
* @description convert union to intersection
277277
* @link https://stackoverflow.com/a/50375286
278278
* @returns {{a} & {b}}
279-
* @example UnionToIntersection<{a:1} | {b:1}> => {a: 1} & {b: 1}
279+
* @example IntersectUnion<{a:1} | {b:1}> => {a: 1} & {b: 1}
280280
*/
281-
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
281+
export type IntersectUnion<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
282282

283283

284284
/**
@@ -290,7 +290,7 @@ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) ex
290290
* @returns {boolean}
291291
* @example IsUnion<{a:1} | {b:1}> => true
292292
*/
293-
export type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true
293+
export type IsUnion<T> = [T] extends [IntersectUnion<T>] ? false : true
294294

295295

296296

@@ -340,15 +340,15 @@ declare const __brand: unique symbol
340340
* @protected - popular type
341341
* @description branded type
342342
*/
343-
export type ScreenType<T, B = never> = T & { [__brand]?: B }
343+
export type ScreenType<T, B = never> = T & { readonly [__brand]?: B }
344344

345345

346346

347347
/**
348348
* @requires ^4.2.3
349349
* @cat union
350350
* @description Extract last or first type from union type
351-
*
351+
* @TODO rename to {PopFrom}
352352
*/
353353
type FirstOrLast_<U extends PropertyKey> = (U extends any ? (x: () => U) => void : never) extends (x: infer P) => void
354354
? P extends () => infer Return ? Return : never
@@ -369,5 +369,23 @@ export type ObjectLength<O extends object, Res extends PropertyKey[] = [], L ext
369369
: ObjectLength<Omit<O, L>, [L, ...Res]>;
370370

371371

372+
373+
/**
374+
* @cat Object | Array
375+
* @param {O} object
376+
* @param {*} S replaced type
377+
* @param {*} R new type
378+
* @description deep replace all fields with specified type S to type R in object O
379+
* @return {object}
380+
* @example ['', '', 5], string, 0 => [0, 0, 5]
381+
*/
382+
export type ReplaceTypes<O extends object, S, R> = {
383+
[K in keyof O]: O[K] extends object
384+
? ReplaceTypes<O[K], S, R>
385+
: O[K] extends S ? Exclude<O[K], S> | R : O[K]
386+
}
387+
388+
389+
372390
//@see also:
373391
// https://stackoverflow.com/questions/62084836/what-does-it-mean-for-a-type-to-distribute-over-unions

0 commit comments

Comments
 (0)