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

The recommended way to ignore “property does not exist on value of type” #6436

Closed
redstrike opened this issue Jan 11, 2016 · 1 comment
Closed
Labels
Question An issue which isn't directly actionable in code

Comments

@redstrike
Copy link

I need to override an experiment property in Chrome and encounter this error.

if ('scrollRestoration' in history) {
    history.scrollRestoration = 'manual'; // type error
}

I found the answers at: http://stackoverflow.com/questions/18083389/ignore-typescript-errors-property-does-not-exist-on-value-of-type. But not sure which one is the right way to go.

(history as any).scrollRestoration = 'manual';

vs

history['scrollRestoration'] = 'manual';

It seems that TypeScript's docs / deep dive book doesn't mention about the squared brackets syntax.

@ahejlsberg
Copy link
Member

I'd go with the first one. The second one works, but only if you compile without -noImplicitAny.

@ahejlsberg ahejlsberg added the Question An issue which isn't directly actionable in code label Jan 11, 2016
@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.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

2 participants