Skip to content

deno publish / don't accept imported function as default parameter #27575

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

Closed
foobar-maker opened this issue Jan 7, 2025 · 2 comments · Fixed by #27581
Closed

deno publish / don't accept imported function as default parameter #27575

foobar-maker opened this issue Jan 7, 2025 · 2 comments · Fixed by #27581
Labels
bug Something isn't working correctly publish Related to "deno publish" subcommand

Comments

@foobar-maker
Copy link

Version: Deno 2.1.4

when I try to deno publish with the following code, i have the error

TS2304 [ERROR]: Cannot find name 'add'.
export const useFn = (...[a, b, fn = add]: [bigint, bigint, (a: bigint, b: bigint) => bigint]): bigint =>({} as never);

Is the bug coming from deno or Typescript ?

Source code

// deno publish is KO
// add module is
// export const add = (a:bigint,b:bigint):bigint => { return a + b};

import { add } from "./add.ts";

export const useFn = (
    ...[a, b, fn = add]
  ): bigint => {
    return fn(a, b);
  }

console.log(useFn(1n, 2n)); // 3n
console.log(useFn(1n, 2n, (a,b)=>a*b)); // 2n

When you have no import, it works

// deno publish => OK
export const add = (a:bigint,b:bigint):bigint => { return a + b};

export const useFn = (
    ...[a, b, fn = add]
  ): bigint => {
    return fn(a, b);
  }

console.log(useFn(1n, 2n)); // 3n
console.log(useFn(1n, 2n, (a,b)=>a*b)); // 2n
@marvinhagemeister marvinhagemeister added bug Something isn't working correctly publish Related to "deno publish" subcommand labels Jan 7, 2025
@dsherret dsherret added the needs info needs further information to be properly triaged label Jan 7, 2025
@dsherret
Copy link
Member

dsherret commented Jan 7, 2025

I'm not able to reproduce this. I get a different error about not having an explicit type. Maybe I'm missing something, but can you try out the example you posted and update it if necessary? At the least, please provide the exact deno publish command you're running. Thanks!

@foobar-maker
Copy link
Author

I only run deno publish with the setup below (I deleted typescript type on my first post to focus only on fn=add, sorry)

add.ts

export const add = (a:bigint,b:bigint):bigint => { return a + b};

mod.ts

import { add } from "./add.ts";

export const useFn = (
    ...[a, b, fn = add]: [bigint, bigint, (a: bigint, b: bigint) => bigint]
  ): bigint => {
    return fn(a, b);
  }

deno.jsonc

{
    "name": "@xxx/test-function",
    "version": "0.0.1-alpha",
    "license": "MIT",
    "exports": "./mod.ts",
    "lock": false,
    "lint": {
      "rules": {
        "tags": [
          "recommended"
        ]
      }
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly publish Related to "deno publish" subcommand
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants