Skip to content
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

fix(types/unstable): better type hints for Deno.dlopen (close: #16873) #16874

Merged
merged 5 commits into from
Dec 3, 2022

Conversation

ahaoboy
Copy link
Contributor

@ahaoboy ahaoboy commented Nov 30, 2022

close #16873
Use magic code wrap parameters type and get more accurate return type

  type Cast<A, B> = A extends B ? A : B;
  type Const<T> = Cast<
    T,
    | (T extends string | number | bigint | boolean ? T : never)
    | { [K in keyof T]: Const<T[K]> }
    | []
  >;
declare function f<T>(arg: Const<T>): T;


let r = f({
  a: {
    b: 1,
    c: "2",
  },
});

image

@CLAassistant
Copy link

CLAassistant commented Nov 30, 2022

CLA assistant check
All committers have signed the CLA.

@ahaoboy ahaoboy changed the title fix(types/unstable): better type hints for Deno.dlopen (close: ##16873) fix(types/unstable): better type hints for Deno.dlopen (close: #16873) Nov 30, 2022
@littledivy
Copy link
Member

Thank you for the PR @ahaoboy

Can you add type tests in test_ffi/tests/ffi_types.ts ?

@ahaoboy
Copy link
Contributor Author

ahaoboy commented Dec 1, 2022

@littledivy
I remove all as const in test_ffi/tests/ffi_types.ts, This tick also works for both UnsafeCallback and UnsafeFnPointer.

@littledivy littledivy merged commit 8b5b327 into denoland:main Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[types/unstable] Deno.dlopen's type need to be more accurate
4 participants