You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the limitations of typia is the inability to set types as generics. This creates a number of constraints, which are unfortunately difficult to resolve. To mitigate some of these constraints, I propose the introduction of a typia.transform function.
typia.transform takes a single function f: (x: any) => any as its argument. The returned value is promisified as the base typia module, and data is processed through the argument function and awaited before being passed on. In other words, await typia.transform(f).is<Data>(x) is equivalent to typia.is<Data>(await f(x)). This function will allow for wrapping typia without using generics, which is currently impossible due to the aforementioned limitations, forcing us to return the functions as they are.
Consider the following scenario: We wish to create a wrapper function for typia.assert that takes a numeric ID, calls an API, and asserts the type of the response. Using the proposed method, we could create a wrapper function as follows:
Currently, to achieve similar functionality, we must pass a checker function to each function as mentioned in issue #125, which is less convenient than the example provided.
If there are existing solutions that I have overlooked, I would greatly appreciate your input.
The text was updated successfully, but these errors were encountered:
seo-rii
changed the title
Feature Request: typia.transform
Feature Request: typia.transform - delayed type specification
Feb 17, 2024
One of the limitations of
typia
is the inability to set types as generics. This creates a number of constraints, which are unfortunately difficult to resolve. To mitigate some of these constraints, I propose the introduction of atypia.transform
function.typia.transform
takes a single functionf: (x: any) => any
as its argument. The returned value is promisified as the basetypia
module, and data is processed through the argument function and awaited before being passed on. In other words,await typia.transform(f).is<Data>(x)
is equivalent totypia.is<Data>(await f(x))
. This function will allow for wrappingtypia
without using generics, which is currently impossible due to the aforementioned limitations, forcing us to return the functions as they are.Consider the following scenario: We wish to create a wrapper function for
typia.assert
that takes a numeric ID, calls an API, and asserts the type of the response. Using the proposed method, we could create a wrapper function as follows:Currently, to achieve similar functionality, we must pass a checker function to each function as mentioned in issue #125, which is less convenient than the example provided.
If there are existing solutions that I have overlooked, I would greatly appreciate your input.
The text was updated successfully, but these errors were encountered: