Skip to content

Import missing in declaration when destructuring with computed keys #26185

@peterhorne

Description

@peterhorne

TypeScript Version: 3.1.0-dev.20180802

Search Terms: missing import in declarations, destructuring with imported constant

Code

context.ts

export const Key = Symbol();
export interface Context {
  [Key]: string;
}

index.ts

import { Key, Context } from "./context";

export const context: Context = {
  [Key]: 'bar',
}

export const withContext = ({ [Key]: value }: Context) => value;

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true
  }
}

Expected behavior:
Generated declaration index.d.ts references Key and so it should also import it.

Actual behavior:
Key is referenced in the signature of withContext but does not import it:

import { Context } from "./context"; // Key is missing from this import
export declare const context: Context;
export declare const withContext: ({ [Key]: value }: Context) => string;
//                                    ^^^ Key is referenced here

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts files

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions