Check if object is a function if the type idicates so#159
Check if object is a function if the type idicates so#159rhys-vdw merged 3 commits intorhys-vdw:masterfrom chomosuke:master
Conversation
|
Hey @chomosuke, looks good to me. Thanks for the contribution. Sorry for the delay, for some reason CI isn't running on external PRs so I had to find a moment to test it locally. FWIW I think the warning is unnecessary, but happy to go with your preference on this one. You've been invited as a collaborator. If you do accept there is no obligation on you to contribute, but I ask that you add test coverage to any PRs you open and try to get at least one other collaborator to review before merging. |
|
It's not necessary to add test coverage, but if you want to check output you'd do it something like this: https://javascript.plainenglish.io/how-to-test-stdout-output-in-node-js-6c36edc610d1 |
|
Hey @rhys-vdw, Thanks for the invite. I will probably add test coverage for the warning anyway just for good measure. |
|
I'm getting the warning: ... but can't get rid of it with: /** @see {isSchemaResult} ts-auto-guard:type-guard */
export type SchemaResult<T extends SchemaRule = SchemaRule> = {
required: boolean;
nullable?: boolean;
rule: T;
// ts-auto-guard-suppress function-type
sanitize?: (val: any) => any;
excludeOptional?: boolean;
};Am I doing something wrong? |
|
I think you need to put that comment above the type declaration, not the field @pkyeck. if that doesn't work please make a new issue, this one is closed. |
closes #155.
If a properties has a function type, it checks if the object is actually a function in the type guard.
It would also emit a warning regarding how the signature of the function will never be tested in the type guard. The warning can be suppressed by putting comment
ts-auto-guard-suppress function-typebefore the declaration. I'm happy to change the warning or the way the warning is suppressed.I tried to find out how to test the warning in console output with tape but to no avail. If anyone know how to do it please tell me or you tackle it yourself. Otherwise we'll probably have to make do with the fact that the emitted warning will not be tested.