Skip to content

Get rid of @as(json hack for default arguments of external functions #7027

Open

Description

@cknitt

Currently, default arguments for bindings to external functions can be supplied with

@as(json`someLiteral`) _

where someLiteral is a JS number, string or object literal.

This is used in several bindings, like in this example (adapted from rescript-react-native):

@val
external unsafeAddStyle: (@as(json`{}`) _, style, {..}) => style = "Object.assign"

Unfortunately, the implementation of this feature in the compiler is quite hacky, requiring special handling for both tagged strings and function arity.

We should therefore try to find a better, but still zero-cost mechanism to replace it.

We discussed that a possible direction to explore would be "zero cost raw functions", meaning that the above example could be written as something like the following, with raw JS code as the function definition:

@rawFunction
external unsafeAddStyle: (style, {..}) => style = "(style, obj) => Object.assign({}, style, obj)"

This means that the raw JS function definition would be inlined where the external is used.

Activity

  1. github-actions commented on Sep 4, 2025

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  2. added
    stale
    on Sep 4, 2025
  3. removed
    stale
    on Sep 4, 2025
  4. added this to the v13 milestone on Dec 4, 2025
  5. github-actions commented on Nov 30, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  6. added
    stale
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementstale

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions