镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Get return type of interface function #16372

Closed

Description

@pie6k

I've got object that has some function that returns various types. I have another object that is aware of the first object, and I need to know return type of function from first object

Example:

I've got first object like:

const tokens = {
  // key below is name of token
  month: {
    possibleValues: ['jan', 'feb'], // etc...
    filter: (monthName: string): number => {
      return 12; // will return number 1-12
    }, 
  },
  weekday: {
    possibleValues: ['mon', 'tue'], // etc
    filter: (monthName: string): Date => {
      return new Date(); // will return Date of weekday
    },
  },
};

// as seen above - filter of 'month' always returns number and filter of 'weekday' returns Date

const parser: Parser<typeof tokens> {
  parseWeekday: ({ weekday, month }) => {
    // weekday should be detected to be Date type
    // month should be detected to be number type
  }
}

Is that possible?

Activity

  1. mhegazy commented on Jun 8, 2017

    @mhegazy
    Contributor

    duplicate of #6239, tracked by #6606

  2. mhegazy commented on Aug 17, 2017

    @mhegazy
    Contributor

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

  3. 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

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions