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

incremental typing of objects #31854

Closed
MarcWeber opened this issue Jun 11, 2019 · 3 comments
Closed

incremental typing of objects #31854

MarcWeber opened this issue Jun 11, 2019 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@MarcWeber
Copy link

Search Terms

dictionary

Suggestion

Sometimes I want to do something like:

const a = {}
a.foo = () => {}
a.bar = () => { a.foo(); }

-> but this is hard to type because the a.bar cannot change the type of a.
You can give a type with foo? bar? but its all a mess.

I tried quora, irc and gitter -> but didn't get a reply whether this is possible.

Its a eventually a complicated topic because if a was used somewhere else and
you do 'destructive' updates such as changing types other code might be affected.

So this would require introducing tracking what is being done with it.

In cases like above it looks trivial.

Note

This could be a duplicate. Thus if you know a proposal/solution kindly point to it. I failed finding it.

@dragomirtitian
Copy link
Contributor

This would be analogous to the way arrays are gradually typed under noImplictAny:

let a = [];
a.push(1);
a[0].toExponential // a is number[]

@RyanCavanaugh
Copy link
Member

Duplicate #12416

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 13, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants