Io-ts: Function is deprecated without a clear alternative

Created on 3 May 2019  路  2Comments  路  Source: gcanti/io-ts

Do you want to request a _feature_ or report a _bug_?
Bug

What is the current behavior?
Usage of t.Function is marked as deprecated without a clear alternative.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://codesandbox.io/ or similar.
Look at the docs to see that t.Function is deprecated. Or run tslint with tslint-config-standard on code using t.Function to see it complain about deprecation.

What is the expected behavior?
t.Function should not be marked deprecated, or an alternative type for validating functions should be added.

Which versions of io-ts, and which browser and OS are affected by this issue? Did this work in previous versions of io-ts?
Current version: 1.8.7, worked in versions prior to 1.8.3

Most helpful comment

@gcanti Why is it an all or nothing scenario? There are many use cases for validating that a value is, at the very least, a function even if there's no way to check the signature.

For example, we have libraries written in typescript that are used in plain javascript runtimes and io-ts is used to validate that the arguments passed in conform to the static typescript types. A common occurrence would be passing in an options object containing a callback or event handler attribute. t.Function would be used inside the options object type to verify at runtime that the attribute really is a function and our library can safely use it as one. Even if the signature is incorrect that responsibility would fall on the consumer of the library which is in line with expectations of existing nodejs libraries with function parameters.

Considering 'function' is a fundamental type in javascript it doesn't seem sensible to remove it.

All 2 comments

There's no sensible alternative (you can't really validate a function, i.e. its domain and codomain, at runtime) and is deprecated because will be removed in ~io-ts@2~ io-ts@3.

@gcanti Why is it an all or nothing scenario? There are many use cases for validating that a value is, at the very least, a function even if there's no way to check the signature.

For example, we have libraries written in typescript that are used in plain javascript runtimes and io-ts is used to validate that the arguments passed in conform to the static typescript types. A common occurrence would be passing in an options object containing a callback or event handler attribute. t.Function would be used inside the options object type to verify at runtime that the attribute really is a function and our library can safely use it as one. Even if the signature is incorrect that responsibility would fall on the consumer of the library which is in line with expectations of existing nodejs libraries with function parameters.

Considering 'function' is a fundamental type in javascript it doesn't seem sensible to remove it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steida picture steida  路  7Comments

leemhenson picture leemhenson  路  6Comments

ggoodman picture ggoodman  路  8Comments

cyberixae picture cyberixae  路  3Comments

rjhilgefort picture rjhilgefort  路  6Comments