/
index.ts
41 lines (40 loc) · 1.11 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as Debug from './debug';
export { Debug };
/**
* C++ style operator, a syntactic sugar for writing casts like
* `value as any as T` when a simple `value as T` cast cannot be performed.
* Use it with caution!
*
* @param target value to cast by any means to T.
*
*
* @remarks
* This function is actually noop at runtime, all it does is it suppresses
* 'inability to cast' tsc error. It's better to use this function rather than
* `value as any as T` cast, because it amplifies your attention to such uneven
* places in code and it may be easier to do a Ctrl + F search for these.
*
* ```ts
* import { DeepPartial, RemoveKeys, reinterpret } from 'ts-typedefs';
*
* interface User {
* // ...
* }
* type UserUpdate = DeepPartial<RemoveKeys<User, 'password'>>;
*
* const userUpd: UserUpdate = // ...
*
* Object.assign(userUpd, {
* password: 'somepassword-pfff', otherRequiredFields: // ...
* });
*
* let user = reinterpret<User>(userUpd); // Here userUpd has the same shape as `User`
* // `typeof user` is `User`
*
* ```
*
*
*/
export function reinterpret<T>(value: any): T {
return value;
}