Skip to content

Function can return wrong values despite type #30603

Closed
@bjornua

Description

@bjornua

TypeScript Version: 3.4.0-dev.20190326

Search Terms: Function Generic Extends Keyof Property

Code

interface Type {
  a: 123;
  b: "some string";
}

function get123<K extends keyof Type>(): Type[K] {
  return 123;
}

Expected behavior:
The function get123 would yield an error as the return type might not be correct as it depends on K.

Actual behavior:
No error for get123. That function would obviously always return 123.

Playground Link: Example on TypeScript Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixedFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions