-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
genType doesn't check typecheck imports from typescript into rescript #6947
Comments
Good catch. This is unintended. I think it is more like a design-space issue, not an implementation bug The addition of |
Runtime binding will be completely removed from #6196 The problem is that it is no longer checked even from tsc. I could make it generate an additional hidden type to force tsc to check it, but that would be easily opt-out by |
Hey, thanks for the reply, sorry I missed it as I was AFK.
Could you elaborate or reword this? I'm struggling to fully understand! What is no longer checked from tsc? And what kind of hidden type are you thinking of? |
@benadamstyles Of course. The next version of genType output will be "library types". It will only have The ReScript compiler fully verifies the output, but you can still force unsafe definitions using E.g. input: @genType.import(("external-module", "Type"))
type t = string
let print = (t: t) => Console.log(t) output: export type t = import("external-module").Type;
export const print: (t: t) => void; Then, if the actual external type is type $GenTypeImport<Expected, T extends Expected> = T;
export type t = $GenTypeImport<string, import("external-module").Type>;
// ^ Type 'number' does not satisfy the constraint 'string'.
export const print: (t: t) => void; This may solve the issue, but still is not a complete solution. A few minor problems:
|
@cometkim Ok thanks, I get it. And what about other kinds of |
There is no particular restriction on specifying types on the ReScript side. It is a kind of assertion for FFI, and additional validation should be done by tsc. |
Rescript v11.1.3
Writing the following code:
generates the following typescript:
This should fail tsc typechecking, because the API of
createClient
is(string, string)
, not(int, string)
. It doesn't however, because ofcreateClientNotChecked as any
. Simply removing thatas any
makes tsc complain and therefore fixes this issue.At first I thought this was a deliberate change from previous versions of genType, and asked about that on the forum, but now I think that it's a bug due to the wording of the comment in the generated typescript:
// In case of type error, check the type of 'createClient' in 'Supabase.res' and '@supabase/supabase-js'.
I would argue that the generated code is not doing what that comment says it is doing.
Maybe I have made a mistake somewhere 😅 thanks for your help!
The text was updated successfully, but these errors were encountered: