Skip to content

autocompletion failing in 3.7.1-rc #34825

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
chandu0101 opened this issue Oct 30, 2019 · 2 comments · Fixed by #34855
Closed

autocompletion failing in 3.7.1-rc #34825

chandu0101 opened this issue Oct 30, 2019 · 2 comments · Fixed by #34855
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@chandu0101
Copy link

chandu0101 commented Oct 30, 2019

TypeScript Version: 3.7.1-rc

Search Terms:

Code

export type GeMethodsForType<T, G extends string> = { [K in keyof T]:
    T[K] extends () => any ? { name: K, group: G, } : T[K] extends (s: infer U) => any ? { name: K, group: G, payload: U } : never }[keyof T];


class Sample {
    count = 0;
    books: { name: string, year: number }[] = []
    increment() {
        this.count++
        this.count++
    }

    addBook(book: Sample["books"][0]) {
        this.books.push(book)
    }
}
export declare function testIt<T, G extends string>(): (input: any, method: GeMethodsForType<T, G>) => any


const t = testIt<Sample, "Sample">()

const i = t(null, { name: "addBook", group: "Sample", payload: { } }) // auto completion for payload

Expected behavior:
Propeties of payload should come in autocompletion
Actual behavior:
No autocompletion
Playground Link: play ground nightly

Working fine in 3.7 beta and 3.6.x

play ground 3.7 beta

Looks like its getting confused when some properties doesn't contain payload property in this case increment method , if i change GeMethodsForType to

export type GeMethodsForType<T, G extends string> = { [K in keyof T]:
    T[K] extends () => any ? { name: K, group: G, payload?:undefined} : T[K] extends (s: infer U) => any ? { name: K, group: G, payload: U } : never }[keyof T]; // payload added  empty arg methods

now autocompletion working fine in 3.7.1-rc :s

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Oct 30, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.7.2 milestone Oct 30, 2019
@andrewbranch
Copy link
Member

andrewbranch commented Oct 31, 2019

This is a regression due to #33937 😕

Simplified:

interface Sample {
    addBook: { name: string, year: number }
}

export declare function testIt<T>(method: T[keyof T]): any
testIt<Sample>({  });

@andrewbranch
Copy link
Member

Update: fixed my simplified test case, but the original repro is still failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants