Skip to content

Extract method with imported generic types results in error #19328

Closed

Description

@mjbvz

From Justin (@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

Activity

  1. weswigham commented on Oct 31, 2017

    @weswigham
    Member

    Duplicates #19395 (just a different surfacing of the same underlying bug)

  2. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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