Skip to content

Better ReturnType<>; Fixes Microsoft/TypeScript#33457 #33496

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
wants to merge 1 commit into from

Conversation

AnyhowStep
Copy link
Contributor

Please verify that:

  • There is an associated issue in the Backlog milestone (required)
  • Code is up-to-date with the master branch
  • You've successfully run gulp runtests locally
  • There are new or updated unit tests validating the change

Fixes #33457

There's no issue in the Backlog but I figured I'd try anyway =x
It fixes my issue and only affects one other test.

But that one other test seems to only have its type emit affected?

type T19<T extends any[]> = ReturnType<(x: string, ...args: T) => T[]>;

is emitted as,

ReturnType<(x: string, ...args: T) => T[]>;

But when a concrete T is substituted in, it resolves to T[]

@typescript-bot
Copy link
Collaborator

It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src'. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src'.

1 similar comment
@typescript-bot
Copy link
Collaborator

It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src'. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src'.

@AnyhowStep
Copy link
Contributor Author

Oh. TS bot sent me a warning. Should I close this and open a PR with lib untouched?

@typescript-bot
Copy link
Collaborator

It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src'. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src'.

@AnyhowStep
Copy link
Contributor Author

AnyhowStep commented Sep 18, 2019

Related,

#33495

The type parameter constraint and RHS of conditional type I'm using are different because of the issue outlined there.

Also, is TS bot borked or is it supposed to say that after every comment?

@typescript-bot
Copy link
Collaborator

It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src'. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src'.

1 similar comment
@typescript-bot
Copy link
Collaborator

It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src'. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src'.

@typescript-bot
Copy link
Collaborator

It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src'. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src'.

@AnyhowStep
Copy link
Contributor Author

@weswigham just thought I'd show you that the TS bot hated it when I touched lib, too =P

@@ -1466,7 +1466,7 @@ type ConstructorParameters<T extends new (...args: any) => any> = T extends new
/**
* Obtain the return type of a function type
*/
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
type ReturnType<T extends (...args: any) => any> = T extends (...args: never) => infer R ? R : any;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ReturnType generic parameter constraint needs to be changed too.

Also, try using never[] instead of just never, maybe that helps.

@AnyhowStep
Copy link
Contributor Author

AnyhowStep commented Dec 1, 2019

export type AnyFunction = (...args: never[]) => void;

I'd just like to point out that ...args : never[] is used by the TS code base at the moment.
Just a random thought.


export type AnyFunction = (...args: never[]) => void;
//Expected: void
//Actual: any
type x = ReturnType<AnyFunction>;

@sandersn
Copy link
Member

sandersn commented Mar 9, 2020

This PR hasn't seen any activity for quite a while, so I'm going to close it to keep the number of open PRs manageable. Feel free to open a fresh PR or continue the discussion on one of the linked bugs.

@sandersn sandersn closed this Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReturnType<> broken with never in parameter
5 participants