@siyavuyachagi/typesharp 0.1.2 → 0.1.3
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 +75 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,34 +14,34 @@ Project structure: [docs/project-structure](docs/project-structure.md)
|
|
|
14
14
|
|
|
15
15
|
## Features
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
- **Automatic Type Generation** – Convert C# models to TypeScript interfaces
|
|
18
|
+
- **Custom Attribute Targeting** – Use `[TypeSharp]` or any custom attribute
|
|
19
|
+
- **Nullable Support** – `string?` → `string | null`
|
|
20
|
+
- **Collection Handling** – Supports `List<T>`, `IEnumerable<T>`, arrays **and generic collections**
|
|
21
|
+
- **Dictionary Mapping** – `Dictionary<K, V>` → `Record<K, V>`
|
|
22
|
+
- **Generic Types** – Preserves generic type definitions like `Response<T>` → `Response<T>`
|
|
23
|
+
- **Inheritance** – Preserves class inheritance using `extends`
|
|
24
|
+
- **Computed Properties** – Expression-bodied and block getter properties are included
|
|
25
|
+
- **Naming Conventions** – Convert property names (camel, pascal, snake, kebab)
|
|
26
|
+
- **Flexible Output** – Single file or multiple files
|
|
27
|
+
- **Enum Support** – Converts C# enums to TypeScript string enums
|
|
28
|
+
- **File Grouping** – Preserves C# file organization (multiple classes per file stay together)
|
|
29
|
+
- **Auto Imports** – Automatically generates `import type` statements between output files
|
|
30
|
+
- **Multi-Project** – Scan multiple `.csproj` files in a single run
|
|
31
|
+
- **Obsolete Support** – `[Obsolete]` / `[Obsolete("...")]` → `/** @deprecated ... */` JSDoc
|
|
32
32
|
|
|
33
33
|
## How TypeSharp Compares
|
|
34
34
|
|
|
35
35
|
This is not an OpenApi-based tool !
|
|
36
36
|
| Feature | TypeSharp | NSwag | openapi-typescript | TypeGen |
|
|
37
37
|
| --------------------- | --------- | ----- | ------------------ | ------- |
|
|
38
|
-
| Direct C# parsing |
|
|
39
|
-
| Attribute targeting |
|
|
40
|
-
| Non-API models |
|
|
41
|
-
| Generics preserved |
|
|
42
|
-
| File grouping |
|
|
43
|
-
| Naming control |
|
|
44
|
-
| API client generation |
|
|
38
|
+
| Direct C# parsing | ✓ | ✕ | ✕ | ✓ |
|
|
39
|
+
| Attribute targeting | ✓ | ! | ✕ | ! |
|
|
40
|
+
| Non-API models | ✓ | ✕ | ✕ | ✓ |
|
|
41
|
+
| Generics preserved | ✓ | ! | ! | ! |
|
|
42
|
+
| File grouping | ✓ | ✕ | ✕ | ✕ |
|
|
43
|
+
| Naming control | ✓ | ! | ! | ✕ |
|
|
44
|
+
| API client generation | ✕ | ✓ | ✕ | ✕ |
|
|
45
45
|
|
|
46
46
|
Also see [docs/why-typesharp](docs/why-typesharp.md)
|
|
47
47
|
|
|
@@ -53,20 +53,18 @@ npm install -D @siyavuyachagi/typesharp
|
|
|
53
53
|
|
|
54
54
|
## Quick Start
|
|
55
55
|
|
|
56
|
-
### 1.
|
|
56
|
+
### 1. Install the NuGet attributes package
|
|
57
57
|
|
|
58
|
-
In your
|
|
58
|
+
In your C# project:
|
|
59
59
|
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
{
|
|
63
|
-
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum)]
|
|
64
|
-
public class TypeSharpAttribute : Attribute { }
|
|
65
|
-
}
|
|
60
|
+
```bash
|
|
61
|
+
dotnet add package TypeSharp.Attributes
|
|
66
62
|
```
|
|
67
63
|
|
|
68
64
|
### 2. Decorate your C# models or DTOs
|
|
69
65
|
|
|
66
|
+
Use `[TypeSharp]` to include a class, or `[TypeSharp("name")]` to include it with a custom TypeScript type name:
|
|
67
|
+
|
|
70
68
|
```csharp
|
|
71
69
|
[TypeSharp]
|
|
72
70
|
public class User
|
|
@@ -263,7 +261,7 @@ TypeSharp supports multiple configuration formats:
|
|
|
263
261
|
|
|
264
262
|
```json
|
|
265
263
|
{
|
|
266
|
-
"
|
|
264
|
+
"source": ["C:/Users/User/Desktop/MyApp/Domain/Domain.csproj"],
|
|
267
265
|
"outputPath": "./src/types"
|
|
268
266
|
}
|
|
269
267
|
```
|
|
@@ -274,7 +272,7 @@ TypeSharp supports multiple configuration formats:
|
|
|
274
272
|
import { TypeSharpConfig } from "typesharp";
|
|
275
273
|
|
|
276
274
|
const config: TypeSharpConfig = {
|
|
277
|
-
|
|
275
|
+
source: ["C:/Users/User/Desktop/MyApp/Domain/Domain.csproj"],
|
|
278
276
|
outputPath: "./src/types",
|
|
279
277
|
};
|
|
280
278
|
|
|
@@ -285,7 +283,7 @@ export default config;
|
|
|
285
283
|
|
|
286
284
|
```javascript
|
|
287
285
|
module.exports = {
|
|
288
|
-
|
|
286
|
+
source: ["C:/Users/User/Desktop/MyApp/Domain/Domain.csproj"],
|
|
289
287
|
outputPath: "./src/types",
|
|
290
288
|
};
|
|
291
289
|
```
|
|
@@ -403,6 +401,7 @@ export interface PermissionMap {
|
|
|
403
401
|
### 4. Obsolete / Deprecated Properties
|
|
404
402
|
|
|
405
403
|
**C#:**
|
|
404
|
+
|
|
406
405
|
```csharp
|
|
407
406
|
[TypeSharp]
|
|
408
407
|
public class Employee
|
|
@@ -419,6 +418,7 @@ public class Employee
|
|
|
419
418
|
```
|
|
420
419
|
|
|
421
420
|
**Generated TypeScript:**
|
|
421
|
+
|
|
422
422
|
```typescript
|
|
423
423
|
export interface Employee {
|
|
424
424
|
id: number;
|
|
@@ -430,7 +430,45 @@ export interface Employee {
|
|
|
430
430
|
}
|
|
431
431
|
```
|
|
432
432
|
|
|
433
|
-
### 5.
|
|
433
|
+
### 5. Custom Type Name Override
|
|
434
|
+
|
|
435
|
+
Use `[TypeSharp("name")]` to override the generated TypeScript type name. The override takes precedence over `namingConvention`.
|
|
436
|
+
|
|
437
|
+
**C#:**
|
|
438
|
+
|
|
439
|
+
```csharp
|
|
440
|
+
[TypeSharp("auth_response")]
|
|
441
|
+
public class AuthResponse
|
|
442
|
+
{
|
|
443
|
+
public string AccessToken { get; set; }
|
|
444
|
+
public string RefreshToken { get; set; }
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
[TypeSharp("user_role")]
|
|
448
|
+
public enum UserRole
|
|
449
|
+
{
|
|
450
|
+
Admin,
|
|
451
|
+
User,
|
|
452
|
+
Guest
|
|
453
|
+
}
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
**Generated TypeScript:**
|
|
457
|
+
|
|
458
|
+
```typescript
|
|
459
|
+
export interface auth_response {
|
|
460
|
+
accessToken: string;
|
|
461
|
+
refreshToken: string;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export enum user_role {
|
|
465
|
+
Admin = "Admin",
|
|
466
|
+
User = "User",
|
|
467
|
+
Guest = "Guest",
|
|
468
|
+
}
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### 6. Multi-Project
|
|
434
472
|
|
|
435
473
|
Scan multiple C# projects at once:
|
|
436
474
|
|
|
@@ -445,7 +483,7 @@ Scan multiple C# projects at once:
|
|
|
445
483
|
}
|
|
446
484
|
```
|
|
447
485
|
|
|
448
|
-
###
|
|
486
|
+
### 7. Single Output File
|
|
449
487
|
|
|
450
488
|
**Config:**
|
|
451
489
|
|
|
@@ -459,7 +497,7 @@ const config: TypeSharpConfig = {
|
|
|
459
497
|
|
|
460
498
|
All types will be generated in `src/types/types.ts`
|
|
461
499
|
|
|
462
|
-
###
|
|
500
|
+
### 8. Custom Naming Conventions
|
|
463
501
|
|
|
464
502
|
**Config:**
|
|
465
503
|
|
|
@@ -517,7 +555,7 @@ generateTypes();
|
|
|
517
555
|
|
|
518
556
|
## Requirements
|
|
519
557
|
|
|
520
|
-
- Node.js >=
|
|
558
|
+
- Node.js >= 20
|
|
521
559
|
- TypeScript >= 4.5 (if using TypeScript config)
|
|
522
560
|
|
|
523
561
|
## License
|
package/package.json
CHANGED