@actualwave/type-checkers
v0.1.13
Published
Framework for parameter/value analysis on access or mutation, used for type check in runtime.
Downloads
9
Readme
JS-Type-Checkers
Library that reports assignments of values or function arguments, return values with wrong types.
const myObj = {
val1: true,
val2: 'string',
method: () => {
return 'str';
},
val3: 123,
list: [],
child: {
val1: true,
val2: 'string',
method: () => {
return {};
},
val3: 123,
},
};
const typeChecked = TypeCheckers.create(myObj);
// this code will work as intended, but type errors should spam
typeChecked.val1 = 'abc';
typeChecked.val2 = {};
// will recognize array and show error
typeChecked.list = {};
// optional parameter "deep" is set to true by default, so all objects coming from properties will be wrapped too
typeChecked.child.val3 = false;
// getting property with wrong type should shows error log too
const myVal = typeChecked.val2;
// save types for method
typeChecked.method(1, 'a', false);
// show error logs for arguments mismatch
typeChecked.method('a', 1, false);
TODOs
- +Add global methods to copy and apply configs, they should work with typeChecker.mergeConfig() method
- +Add possibility to merge objects with type information using mergeConfigs()
- +Decide, when setting value to a property, should this value be wrapped?
- +Decide, when calling function, should arguments and return value be wrapped?
- ?Lazy typings for Arrays or apply one type(from first element) for all items. Indexed type is available, still don't know about lazy arrays
- +Implement "createDeep()"
- Cache child info for arguments
- +Add ability to setup custom value validators for default type checker
- +Ignore accessing functions from prototype all the time
- Add option to ignore any kind of properties available via prototype
- +Implement replaceProperty() -> property()
- +Add possibility to make proxy config be part of target's info
- +Move primitive type checker into separate repo
- Add possibility to register ignored names which will be just skipped whatewer is placed in, probably could be added to ExtendedTypeChecker.
- Add methods to convert info objects into primitives and back so they could be stored, would be good to have a system that permanently stores types info for consecutive runs.