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

No index signature when a generic type has a symbol property #22312

Closed
Conaclos opened this issue Mar 3, 2018 · 2 comments
Closed

No index signature when a generic type has a symbol property #22312

Conaclos opened this issue Mar 3, 2018 · 2 comments
Labels
Fixed A PR has been merged for this issue

Comments

@Conaclos
Copy link

Conaclos commented Mar 3, 2018

Search Terms: "symbol", "no index signature", "symbol enumerable"

Tested TypeScript versions: 2.7.2 and 2.8.0-dev.20180302

Code

declare const SYM: unique symbol
type DecoratedPartial <T> = Partial<T> & {
    [SYM]: Function
}
function traverse <T> (ref: DecoratedPartial<T>): void {
    for (const p in ref) {
        const v = ref[p as keyof DecoratedPartial<T>] // error, see below
    }
    const f = ref[SYM]
}

Expected behavior:

No error when noImplicitAny is enabled.

Actual behavior:

The following error is reported:

error TS7017: Element implicitly has an 'any' type
because type 'DecoratedPartial<T>' has no index signature.

Note that this error only occurs when noImplicitAny is turned on.

Playground Link: play with it. Don't forget to enable noImplicitAny.

Related Issues:
The following issue could be related to:

Workaround:

Write an interface whithout the symbol properties (here Partial), and use this interface for traversing (using type assertions).

...
const v = (ref as Partial<T>)[p as keyof Partial<T>]
...
@Conaclos Conaclos changed the title No index signature when a type has a symbol property No index signature when a generic type has a symbol property Mar 5, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Mar 8, 2018
@mhegazy mhegazy added this to the TypeScript 2.8 milestone Mar 8, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Mar 8, 2018

should be fixed in latest.

@mhegazy mhegazy closed this as completed Mar 8, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Mar 8, 2018

fixed by #22339

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants