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

DOMStringMap is defined as an empty interface - this makes it awkward to use #1852

Closed
sccolbert opened this issue Jan 29, 2015 · 2 comments
Closed
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Revisit An issue worth coming back to

Comments

@sccolbert
Copy link

The DOMStringMap interface is defined as follows:

https://github.com/Microsoft/TypeScript/blob/master/src/lib/dom.generated.d.ts#L10556

interface DOMStringMap {
}
declare var DOMStringMap: {
    prototype: DOMStringMap;
    new(): DOMStringMap;
}

This means it's a compile error to directly access the object properties, but it's also an implicit any error if the --noImplicitAny switch is turned on in the compiler. This makes using a node's dataset somewhat arduous since a cast is required.

I'm not sure if there is some way to declare that an object has arbitrary properties of some given type, but perhaps a minimal working solution would be to give this interface a string indexer:

interface DOMStringMap {
  [key: string]: string;
}
@danquirk
Copy link
Member

Seems like there are a few different methods on this type that aren't currently represented in the .d.ts: https://developer.mozilla.org/en-US/docs/Web/API/DOMStringMap. All of them would still be satisfied with that string indexer signature.

@danquirk danquirk added Bug A bug in TypeScript Revisit An issue worth coming back to Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Jan 29, 2015
@mhegazy mhegazy self-assigned this Jan 30, 2015
@mhegazy mhegazy added this to the TypeScript 1.5 milestone Jan 30, 2015
@saschanaz
Copy link
Contributor

The methods described in MDN are not implemented in any of three major web browsers including Firefox.

W3C: http://www.w3.org/TR/html5/infrastructure.html#domstringmap

I hope TS allow node.dataset.x way as written in W3C example...

@mhegazy mhegazy modified the milestones: TypeScript 1.5, TypeScript 1.6 Feb 5, 2015
@mhegazy mhegazy assigned zhengbli and unassigned mhegazy Apr 7, 2015
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Apr 17, 2015
@mhegazy mhegazy closed this as completed Apr 17, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Revisit An issue worth coming back to
Projects
None yet
Development

No branches or pull requests

5 participants