@alessiofrittoli/type-utils 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/index.d.mts +5 -11
- package/dist/index.d.ts +5 -11
- package/package.json +2 -2
- package/scripts/postinstall/index.js +12 -0
- package/scripts/postinstall/ts-setup.js +33 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Type Utils ❇️
|
|
2
2
|
|
|
3
|
-
Version 0.1.
|
|
3
|
+
Version 0.1.2
|
|
4
4
|
|
|
5
5
|
## Lightweight TypeScript types utilities
|
|
6
6
|
|
|
@@ -55,6 +55,12 @@ Please make sure to add it in the array of the "include" property in your `tscon
|
|
|
55
55
|
|
|
56
56
|
You can skip this process if `*.ts` is already in your "include" array.
|
|
57
57
|
|
|
58
|
+
⚠️ If the `type-utils.d.ts` file creation fails you run the following command to manually execute the script:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
node node_modules/@alessiofrittoli/type-utils/scripts/postinstall/index.js
|
|
62
|
+
```
|
|
63
|
+
|
|
58
64
|
---
|
|
59
65
|
|
|
60
66
|
### [ESLint](https://www.npmjs.com/package/eslint)
|
package/dist/index.d.mts
CHANGED
|
@@ -20,22 +20,16 @@ declare global {
|
|
|
20
20
|
/**
|
|
21
21
|
* Get the Type of the Value of object/array specific property.
|
|
22
22
|
*/
|
|
23
|
-
type
|
|
23
|
+
type ValueOfKey<T, P extends keyof T> = T[P];
|
|
24
24
|
/**
|
|
25
|
-
* Make a specific property
|
|
25
|
+
* Make a specific property optional.
|
|
26
26
|
*/
|
|
27
|
-
type
|
|
28
|
-
/**
|
|
29
|
-
* Make read-only properties of an object writeable.
|
|
30
|
-
*/
|
|
31
|
-
type Writeable<T> = {
|
|
32
|
-
-readonly [P in keyof T]: T[P];
|
|
33
|
-
};
|
|
27
|
+
type OptionalKey<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
34
28
|
/**
|
|
35
29
|
* Make read-only properties of an object recursively writeable.
|
|
36
30
|
*/
|
|
37
|
-
type
|
|
38
|
-
-readonly [P in keyof T]:
|
|
31
|
+
type Writeable<T> = {
|
|
32
|
+
-readonly [P in keyof T]: Writeable<T[P]>;
|
|
39
33
|
};
|
|
40
34
|
/**
|
|
41
35
|
* Renames a property while inheriting its type.
|
package/dist/index.d.ts
CHANGED
|
@@ -20,22 +20,16 @@ declare global {
|
|
|
20
20
|
/**
|
|
21
21
|
* Get the Type of the Value of object/array specific property.
|
|
22
22
|
*/
|
|
23
|
-
type
|
|
23
|
+
type ValueOfKey<T, P extends keyof T> = T[P];
|
|
24
24
|
/**
|
|
25
|
-
* Make a specific property
|
|
25
|
+
* Make a specific property optional.
|
|
26
26
|
*/
|
|
27
|
-
type
|
|
28
|
-
/**
|
|
29
|
-
* Make read-only properties of an object writeable.
|
|
30
|
-
*/
|
|
31
|
-
type Writeable<T> = {
|
|
32
|
-
-readonly [P in keyof T]: T[P];
|
|
33
|
-
};
|
|
27
|
+
type OptionalKey<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
34
28
|
/**
|
|
35
29
|
* Make read-only properties of an object recursively writeable.
|
|
36
30
|
*/
|
|
37
|
-
type
|
|
38
|
-
-readonly [P in keyof T]:
|
|
31
|
+
type Writeable<T> = {
|
|
32
|
+
-readonly [P in keyof T]: Writeable<T[P]>;
|
|
39
33
|
};
|
|
40
34
|
/**
|
|
41
35
|
* Renames a property while inheriting its type.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alessiofrittoli/type-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Lightweight TypeScript types utilities",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Alessio Frittoli",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"main": "./dist/index.js",
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"files": [
|
|
26
|
-
"dist"
|
|
26
|
+
"dist", "scripts"
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "eslint && tsup",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const tsSetup = require( './ts-setup.js' )
|
|
2
|
+
|
|
3
|
+
/** @type {(() => void | Promise<void>)[]} */
|
|
4
|
+
const scripts = [ tsSetup ]
|
|
5
|
+
|
|
6
|
+
const executePostInstall = async () => {
|
|
7
|
+
await Promise.all( scripts.map( async script => {
|
|
8
|
+
await script()
|
|
9
|
+
} ) )
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
executePostInstall()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const fs = require( 'fs' )
|
|
2
|
+
const path = require( 'path' )
|
|
3
|
+
const project = require( '../../package.json' )
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const tsSetup = () => {
|
|
7
|
+
|
|
8
|
+
const projectRoot = process.env.INIT_CWD || process.cwd()
|
|
9
|
+
|
|
10
|
+
if ( ! projectRoot || projectRoot.endsWith( project.name ) ) {
|
|
11
|
+
console.error( 'INIT_CWD is not set. This script must be run during pnpm install.' )
|
|
12
|
+
process.exit( 1 )
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const tsconfigPath = path.resolve( projectRoot, 'type-utils.d.ts' )
|
|
16
|
+
|
|
17
|
+
const data = [
|
|
18
|
+
`/// <reference types="${ project.name }" />`,
|
|
19
|
+
'// NOTE: This file should not be edited'
|
|
20
|
+
].join( '\n\n' )
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
fs.writeFileSync( tsconfigPath, data )
|
|
24
|
+
console.log( '"type-utils.d.ts" has been created at the root of your project.' )
|
|
25
|
+
console.log( 'Please update your tsconfig.json to add this file in your "include" property of your tsconfig.json file.' )
|
|
26
|
+
} catch ( error ) {
|
|
27
|
+
console.error( 'An error occured while creating "type-utils.d.ts" at the root of your project. Some global types may not working as expect.', error )
|
|
28
|
+
process.exit( 1 )
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = tsSetup
|