GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update es5.d.ts by donaldpipowitch · Pull Request #13971 · microsoft/TypeScript

Conversation

@donaldpipowitch

@donaldpipowitch Donald Pipowitch (donaldpipowitch) commented Feb 9, 2017

Copy link
Copy Markdown
Contributor

Before:

const foo = {
  bar: 1,
  baz: 2
};

const keysOfFoo = Object.keys(foo); // string[]

Now:

const foo = {
  bar: 1,
  baz: 2
};

const keysOfFoo = Object.keys(foo); // ("bar" | "baz")[]

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@donaldpipowitch
Update es5.d.ts
d30cc57
@msftclas

Microsoft Contribution License Agreements (msftclas) commented Feb 9, 2017

Copy link
Copy Markdown

Hi Donald Pipowitch (@donaldpipowitch), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

This seems like a small (but important) contribution, so no Contribution License Agreement is required at this point. Real humans will now evaluate your PR.

TTYL, MSBOT;

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-not-required label Feb 9, 2017
@j-oliveras

Jordi Oliveras Rovira (j-oliveras) commented Feb 9, 2017

Copy link
Copy Markdown
Contributor

Related to #12870?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Feb 9, 2017

Copy link
Copy Markdown
Contributor

Thanks for the PR. but as discussed in #12870, we do not believe this is a good change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy Mohamed Hegazy (mhegazy) closed this Feb 9, 2017
@donaldpipowitch

Donald Pipowitch (donaldpipowitch) commented Feb 9, 2017

Copy link
Copy Markdown
Contributor Author

Thank you for the fast reply, but I'm very sad to hear this. It makes working with noImplicitAny a lot harder.

const foo = {
  bar: 'bar',
  baz: 'baz'
};
Object.keys(foo).forEach(key => console.log(foo[key].length));  // error with noImplicitAny

To fix this you need to write console.log((foo as any)[key].length) or const foo: { [key: string]: string; }. I think both solutions are suboptimal :(

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@donaldpipowitch

Donald Pipowitch (donaldpipowitch) commented Feb 9, 2017

Copy link
Copy Markdown
Contributor Author

Mohamed Hegazy (@mhegazy) I can't really follow the arguments from #12870 and I'm not sure that is what I want in most cases. Can you give me an example written in TypeScript where my PR would behave bad? And if I want this behaviour wouldn't it be easier to do this than?:

const foo = {
  bar: 'bar',
  baz: 'baz'
};
Object.keys(foo).forEach(key => console.log(foo[key as string].length));
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Feb 9, 2017

Copy link
Copy Markdown
Contributor
function printProperties(foo: {}) {
    Object.keys(foo).forEach(key => console.log(key.toString())); // Error toString does not exisit on `never` 
}

There is code that looks like this today. changing this would be a breaking change, and would not really provide much value.

you can define your function:

const keys = <{ <T>(o: T): Array<keyof T> }>Object.keys;
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@donaldpipowitch

Donald Pipowitch (donaldpipowitch) commented Feb 10, 2017

Copy link
Copy Markdown
Contributor Author
function printProperties(foo: {}) {
    Object.keys(foo).forEach(key => console.log(key.toString())); // Error toString does not exisit on `never` 
}

So if I say my foo is an empty object, we need a way to say that keys returns an empty array (or for the sake of it an empty array which would contain string), because never[] is wrong.

But I'd argue that foo is typed in wrong way in the first place. The function should be called something like that, if want to print and accept any object:

function printProperties(foo: { [s: string]: any; }) {
    Object.keys(foo).forEach(key => console.log(key.toString()));
}

I'd say that is more explicit and more correct.

There is code that looks like this today.

Granted... if that is the case and you want to avoid a breaking change here, this PR could be postponed. But I'm still not convinced that this "works as intended" as labeled in #12870.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@donaldpipowitch

Donald Pipowitch (donaldpipowitch) commented Apr 24, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Mohamed Hegazy (@mhegazy) Just would like to give some feedback. We use noImplicitAny in our config and colleagues which don't know TypeScript in detail are often confused when they write const foo = { bar: 'hello' }; Object.keys(foo).forEach(key => console.log(foo[key])); and see an error message. It's hard to explain why they have to cast foo to any.

Are there proposals to add some kind of modifier or mapping to certain types? So I can map never to something else just inside Object.keys so this legacy code doesn't throw?

function printProperties(foo: {}) {
    Object.keys(foo).forEach(key => console.log(key.toString()));
}

Or would it be possible to invent some special ignore behaviour so I know when Object.keys gets never the forEach can be ignored? (Just dream code here...)

Or a totally different question: Currently it seems that my PR wasn't merged, because it could be a breaking change. Are there already plans for TypeScript 3.0 and maybe some lists where possible breaking changes could be collected and introduced?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request Apr 24, 2017
Add Object.getOwnPropertyDescriptors definition #15280
Closed
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@donaldpipowitch @msftclas @j-oliveras @mhegazy
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.