Skip to content

Extract method with imported generic types results in error #19328

Closed
@mjbvz

Description

@mjbvz

From @greyepoxy on October 18, 2017 0:0

  • VSCode Version: Code 1.17.1 (1e9d36539b0ae51ac09b9d4673ebea4e447e5353, 2017-10-10T14:24:50.851Z)
  • OS Version: Windows_NT x64 10.0.14393
  • TS version: 2.5.3

Steps to Reproduce:

  1. I have this code:
// In someTypes.ts file
export type Dictionary<T> = {
    [key: string]: T;
  };

export type A = string | string[];

export type B = Dictionary<A>;
// In someOtherFile.ts
import { A, B, Dictionary} from './someTypes';

function doThing(): void {
    const aBunchOfA: Dictionary<B> = {};
    
    aBunchOfA['key'] = { a: 'thing' };
}
  1. Highlight aBunchOfA['key'] = { a: 'thing' }; in someOtherFile.ts
  2. Show Fixes (Ctrl+.) -> extract function into module scope

Expected:

// In someOtherFile.ts
import { A, B, Dictionary} from './someTypes';

function doThing(): void {
    const aBunchOfA: Dictionary<B> = {};
    
    newFunction(aBunchOfA);
}
function newFunction(aBunchOfA: Dictionary<B>) {
    aBunchOfA['key'] = { a: 'thing' };
}

Actual:

// In someOtherFile.ts
import { A, B, Dictionary} from './someTypes';

function doThing(): void {
    const aBunchOfA: Dictionary<B> = {};
    
    newFunction(aBunchOfA);
}
function newFunction(aBunchOfA: { [key: string]: Dictionary; }) { //<-- Dictionary underlined in red
    aBunchOfA['key'] = { a: 'thing' };
}

severity: 'Error'
message: 'Generic type 'Dictionary' requires 1 type argument(s).'
at: '8,50'
source: 'ts'

Reproduces without extensions: Yes

Copied from original issue: microsoft/vscode#36453

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDuplicateAn existing issue was already createdVS Code TrackedThere is a VS Code equivalent to this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions