Skip to content

Built in Symbol and shimming Symbol #8169

Closed
@kitsonk

Description

@kitsonk

TypeScript Version:

1.8.10

Code

import Symbol from './Symbol';

export interface Iterable<T> {
    [Symbol.iterator](): Iterator<T>;
}

In Dojo 2, we provide a shim for Symbol. One of the things we have decided to do as a matter of principal is not modify the global namespace with any of our shims, but provide them as modules where the consumer has to make an explicit dependency on that shim. At runtime, we offload to the native API if present, otherwise we provide replicate functionality.

This pattern works effectively, even when targeting ES6, except for Symbol because of the TypeScript's compiler's insistence that we reference the native one.

Is there a good reason why TypeScript disallows this when targeting ES6? If so, is there any way to provide a transparent shim without modifying the global namespace anyone can think of?

Expected behavior:

No errors when targeting es6.

Actual behavior:

When target is es6 we get the following error:

'Symbol' reference does not refer to the global Symbol constructor object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions