Skip to content

Not inferring return type for Object.prototype extension #15708

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
dyst5422 opened this issue May 9, 2017 · 1 comment
Closed

Not inferring return type for Object.prototype extension #15708

dyst5422 opened this issue May 9, 2017 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@dyst5422
Copy link

dyst5422 commented May 9, 2017

TypeScript Version: 2.3.2

Code

code.ts

Object.prototype.myGet = function myGet() {
  return this
};

const a = { prop1: 2 };

console.log(a.myGet().prop1);

types.d.ts

interface Object {
  myGet(): this;
}

Expected behavior:
Should be able to have correct type on the return of a.get() such that it should know that prop1 exists
Actual behavior:
on compile
TSError: Property 'prop1' does not exist on type 'Object'

@dyst5422
Copy link
Author

dyst5422 commented May 9, 2017

just found #12507 closing

@dyst5422 dyst5422 closed this as completed May 9, 2017
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 9, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants