Skip to content

typeof should be able to apply directly to function calls #54999

Closed as not planned
@Autumn-one

Description

@Autumn-one

Suggestion

🔍 Search Terms

typeof function return

✅ Viability Checklist

My suggestion meets these guidelines:

  • [ x ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [ x ] This wouldn't change the runtime behavior of existing JavaScript code
  • [ x ] This could be implemented without emitting different JS based on the types of the expressions
  • [ x ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • [ x ] This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

The following operations should be supported

// Let's say I already have a function
declare function fn(): string;
// This operation fits well with intuition and existing usage,But it is not yet supported
type ret = typeof fn();

The following is written in the manner now supported

const a1 = fn();
type ret = typeof a1;

It is obvious that the style of writing now supported is redundant,if I use analogy, I think it is like a programming language declaration and initialization. If a programming language supports declaration and initialization separately, then the declaration and initialization written together should also be supported.

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