https://github.com/tsdotnet/reflection
A set of classes and utilities for JavaScript type inspection and validation.
https://github.com/tsdotnet/reflection
reflection runtime-type runtime-typechecking type-assertion type-inspection
Last synced: 10 days ago
JSON representation
A set of classes and utilities for JavaScript type inspection and validation.
- Host: GitHub
- URL: https://github.com/tsdotnet/reflection
- Owner: tsdotnet
- License: mit
- Created: 2020-05-01T17:00:07.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2026-02-04T06:57:30.000Z (24 days ago)
- Last Synced: 2026-02-04T18:07:25.692Z (23 days ago)
- Topics: reflection, runtime-type, runtime-typechecking, type-assertion, type-inspection
- Language: TypeScript
- Size: 950 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#  tsdotnet / reflection
[](https://github.com/tsdotnet/reflection/blob/master/LICENSE)

[](https://www.npmjs.com/package/@tsdotnet/reflection)
A set of classes and utilities for JavaScript type inspection and validation.
## Docs
[tsdotnet.github.io/reflection](https://tsdotnet.github.io/reflection/)
## `TypeValidator`
### Benefits
- Allows for run-time validation and checking of dynamic types as well as integrated **type-guarding**.
- Super easy to use, basically only requires a copy paste.
- Works with literals!
### Usage
#### Step 1: Declare the expected type/interface.
```typescript
interface MyType
{
a: object;
b: string;
c: number;
d: boolean;
e: {
f: string;
g: boolean;
h: [
number,
boolean,
string
];
};
}
```
#### Step 2: Copy the interface as an actual object and `` the validator
The following can be done with pure JavaScript and still work.
```typescript
const myTypeValidator = new TypeValidator(
{
a: Object,
b: String,
c: Number,
d: Boolean,
e: {
f: String,
g: Boolean,
h: [
Number,
Boolean,
String
]
}
});
```
#### Step 3: validate as many times as you want:
```typescript
const myItem = {
a: {},
b: 'hello',
c: 1,
d: true,
e: {
f: 'whatever',
g: false,
h: [
0,
true,
'2'
]
},
i: 'noise'
};
// no compile-time type errors!
if (MyTypeValidator.isSubsetOf(myItem)) {
console.log(myItem.e.h.length); // 3
console.log(myItem.b); // "hello"
} else {
throw new TypeError('Invalid type!');
}
```