You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+110-3Lines changed: 110 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,113 @@ I cannot guarantee you that the transformer covers all possible cases, but it ha
21
21
22
22
Also, it might not work as expected with composite projects, because the project should contain an entry points you set in options, but it might be in other sub-project.
23
23
24
+
## Example
25
+
26
+
Let's say we have the following source code in entry point:
27
+
28
+
```typescript
29
+
// yeah, it's especially without the `export` keyword here
var internalOptions = { _internal_fooBar: fooBar };
54
+
console.log(internalOptions._internal_fooBar);
55
+
return result;
56
+
}
57
+
exports.getOptions= getOptions;
58
+
```
59
+
60
+
Even if both `Options` and `InternalInterface` have the same property `fooBar`, the only `InternalInterface`'s `fooBar` has been renamed into `_internal_fooBar`.
61
+
That's done because this interface isn't exported from the entry point (and even isn't used in exports' types), so it isn't used anywhere outside and could be safely renamed (within all it's properties).
62
+
63
+
## Example 2
64
+
65
+
Let's see more tricky example with classes and interfaces. Let's say we have the following code:
66
+
67
+
```typescript
68
+
exportinterfaceInterface {
69
+
publicMethod(opts:Options, b:number):void;
70
+
publicProperty:number;
71
+
}
72
+
73
+
exportinterfaceOptions {
74
+
prop:number;
75
+
}
76
+
77
+
classClassimplementsInterface {
78
+
public publicProperty:number=123;
79
+
80
+
public publicMethod(opts:Partial<Options>):void {
81
+
console.log(opts.prop, this.publicProperty);
82
+
this.anotherPublicMethod();
83
+
}
84
+
85
+
public anotherPublicMethod():void {}
86
+
}
87
+
88
+
exportfunction interfaceFactory():Interface {
89
+
returnnewClass();
90
+
}
91
+
```
92
+
93
+
Here we can a class `Class` which implements an interface `Interface` and a factory, which creates a class and returns it as `Interface`.
1.`publicProperty`, declared in `Interface` interface and implemented in `Class` class hasn't been renamed,
120
+
because it's accessible from an object, returned from `interfaceFactory` function.
121
+
122
+
1.`publicMethod` hasn't been renamed as well the same as `publicProperty`.
123
+
124
+
1.`prop` from `Options` interface also hasn't been renamed as soon it's part of "public API" of the module.
125
+
126
+
1.`anotherPublicMethod` (and all calls) has been renamed into `_internal_anotherPublicMethod`,
127
+
because it isn't declared in `Interface` and cannot be accessible from an object, returned from `interfaceFactory` publicly (TypeScript didn't even generate types for that!).
128
+
129
+
More examples you can see [in test-cases folder](https://github.com/timocov/ts-transformer-properties-rename/tree/master/tests/test-cases/).
130
+
24
131
## Installation
25
132
26
133
1. Install the package `npm i -D ts-transformer-properties-rename`
0 commit comments