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

proagram doesn't typecheck anymore in 4.9 #51910

Closed
sigmaSd opened this issue Dec 15, 2022 Β· 5 comments
Closed

proagram doesn't typecheck anymore in 4.9 #51910

sigmaSd opened this issue Dec 15, 2022 Β· 5 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@sigmaSd
Copy link

sigmaSd commented Dec 15, 2022 β€’

Bug Report

πŸ”Ž Search Terms

typeof

πŸ•— Version & Regression Information

typescript 4.9

  • This is a compile error
  • This changed between versions 4.8 and 4.9

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

  interface Object {
    pipe<U>(fn: (a: any) => U): U;
}

Object.prototype.pipe = function <U>(fn: (a: typeof this) => U) {
  return fn(this);
};

πŸ™ Actual behavior

errors with

error: TS2304 [ERROR]: Cannot find name 'this'.
Object.prototype.pipe = function <U>(fn: (a: typeof this) => U) {

πŸ™‚ Expected behavior

It used to typecheck in earlier versions

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Dec 15, 2022

This never actually worked

const m = { foo: 3 }.pipe(j => j.baz);
// j: any

I think you want

Object.prototype.pipe = function <U, T>(this: T, fn: (a: T) => U) {
  return fn(this);
};

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 15, 2022
@sigmaSd
Copy link
Author

sigmaSd commented Dec 15, 2022

It works, it seems like you have a typo there, baz instead of foo

@sigmaSd
Copy link
Author

sigmaSd commented Dec 15, 2022

Maybe you mean the types not working ?

I can close this, if this is just all correct, I just want to bring to notice that 4.8 it had no error and 4.9 it does

4.9
4.8

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Dec 15, 2022

It was just a bug that this was allowed in the first place. It doesn't "do" anything without a corresponding this parameter

@sigmaSd
Copy link
Author

sigmaSd commented Dec 15, 2022

thanks

@sigmaSd sigmaSd closed this as completed Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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

2 participants