Skip to content
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

Generic Type Inference Bug? #14037

Closed
evanbb opened this issue Feb 13, 2017 · 3 comments
Closed

Generic Type Inference Bug? #14037

evanbb opened this issue Feb 13, 2017 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@evanbb
Copy link

evanbb commented Feb 13, 2017

TypeScript Version: 2.1.6

Code

declare module 'module' {
  interface result<T> {
    item: T
  }

  export interface resulter {
    <T extends keyof validKeys>(): result<T>
  }

  export interface validKeys {
    validKey: string
  }

  export interface results {
    [key: string]: resulter
  }
}
import { results } from 'module';

const d: results = {
  something: () => ({
    item: 'invalidKey'
  })
};

Expected behavior:
Valid values for 'item' property on result would be restricted to keys of validKeys.

Actual behavior:
Inspecting the error if the 'item' property is removed from the result confirms that the result object is typed as result.

@krryan
Copy link

krryan commented Feb 13, 2017

Related to #13995

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@mhegazy mhegazy added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Needs Investigation This issue needs a team member to investigate its status. labels Feb 8, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Feb 8, 2018

Not sure i understand what the use of a generic signature here is meant to enforce. but either ways, the function API says it can be called with any T, and it will somehow return you a result of the same T passed..

d.something<"validKey">();  // result<"validKey">
d.something<"anotherValidKey">();  // result<"anotherValidKey">

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants