镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Inferred implicit any accessor type in object literal #8373

Description

@kitsonk

TypeScript Version:

nightly (1.9.0-dev.20160429)

Code

const foo = {
    _foo: 'bar',
    get foo() { // <- 'foo' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
        return this._foo;
    },
    set foo(value) { // <- 'value' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
        this._foo = value;
    }
};

Expected behavior:

No errors.

Actual behavior:

With the compiler option noImplicitAny = true and inferred object literal typing, the compiler is complaining that get and set accessors have inferred any types, when though it is logical that the type of string can be inferred from the context (or at least I am missing the reason why it cannot be inferred).

Activity

  1. sandersn commented on May 3, 2016

    @sandersn
    Member

    It doesn't repro for me on master. I thought the nightly from 04/29 would have the commits to revert object literal this typing to always be any, but maybe it doesn't. Let me figure out which commit 1.9.0-dev.20160429 is built from.

    It does have errors all over the place with --noImplicitThis. Could that be what you're using?

  2. kitsonk commented on May 3, 2016

    @kitsonk
    ContributorAuthor

    I found it... --strictNullChecks on for 1.9.0-dev.20160429 it will not cause the behaviour. If you turn --strictNullChecks off on 1.9.0-dev.20160429 it will manifest itself, but isn't present at all (either configuration) on 1.9.0-dev.20160503. Not sure what broke/fixed it... 😄

  3. sandersn commented on May 3, 2016

    @sandersn
    Member

    I didn't have time to check the commit that the 20160429 nightly used, but it's probably the change I made that reverts this in object literals to any. I guess it went in too late to get picked up by the nightly build.

  4. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: This-TypingThe issue relates to providing types to this

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions