Skip to content

Parameter with object initializer not working with imported function #545

@nicojs

Description

@nicojs

Given this dep.ts file:

// dep.ts
export function dep(str: string) {
  return `dep: ${str}`;
}

And this main.ts file:

// main.ts
import { dep } from "./dep.ts";

function run(context = { dep }) {
  const { dep } = context;
  console.log(dep("Hello, world!"));
}
run();

It does not compile with typescript-go, but does with TypeScript. As far as I know it should be supported with the current compiler.

It provides these errors:
main.ts:3:14 - error TS7022: 'context' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

3 function run(context = { dep }) {
               ~~~~~~~~~~~~~~~~~

main.ts:3:26 - error TS2373: Parameter 'context' cannot reference identifier 'dep' declared after it.

3 function run(context = { dep }) {
                           ~~~

main.ts:3:26 - error TS2448: Block-scoped variable 'dep' used before its declaration.

3 function run(context = { dep }) {
                           ~~~

  main.ts:4:11 - 'dep' is declared here.
    4   const { dep } = context;
                ~~~

main.ts:4:11 - error TS7022: 'dep' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

4   const { dep } = context;
            ~~~


Found 4 errors in the same file, starting at: main.ts:3

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions