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

Map,Set ... in ES5 target #3290

Closed
kyasbal opened this issue May 28, 2015 · 3 comments
Closed

Map,Set ... in ES5 target #3290

kyasbal opened this issue May 28, 2015 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@kyasbal
Copy link

kyasbal commented May 28, 2015

After update the typescript compiler from version 1.4.1 to 1.5.0 beta, the source code included in my project became to make error log such as 'Map is not found'.
Thus, I researched this problem, and I reached an conclusion. The lib.d.ts became not to contain Map and Set definitions except ES6 being selected in tsconfig.json.

Actually, Map and Set is specification of ES6. It is natural that we can't use Map and Set in the project targeting ES5 or lower.
But we could use Map and Set even if I select ES5 as the target before typescript 1.4.1.
I know that making it being enabled to use Map and Set in the project that is made for ES5 contains risk.
Because there is some of browsers not supporting Map and Set.

However, I think it is better to make some of property of configuration that is for switching to use these definitions or not. Don't you think so?

@mhegazy
Copy link
Contributor

mhegazy commented May 28, 2015

@LimeStreem we removed some IE-specific types from the library in 1.5.0-beta. you can just define the type in one of your files like:

interface Map<K, V> {
    clear(): void;
    delete(key: K): boolean;
    forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void;
    get(key: K): V;
    has(key: K): boolean;
    set(key: K, value: V): Map<K, V>;
    size: number;
}
declare var Map: {
    new <K, V>(): Map<K, V>;
    prototype: Map<any, any>;
}
interface Set<T> {
    add(value: T): Set<T>;
    clear(): void;
    delete(value: T): boolean;
    forEach(callbackfn: (value: T, index: T, set: Set<T>) => void, thisArg?: any): void;
    has(value: T): boolean;
    size: number;
}
declare var Set: {
    new <T>(): Set<T>;
    prototype: Set<any>;
}

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label May 28, 2015
@kyasbal
Copy link
Author

kyasbal commented May 28, 2015

Wow, I appreciate you to write this code snippet! 😆
I wonder this issue will help a lot of typescript users!

@nin-jin
Copy link

nin-jin commented Jun 27, 2017

declare class WeakMap< Key , Value > {
	delete( key : Key ) : boolean
	get( key : Key ) : Value
	has( key : Key ) : boolean
	set( key : Key , value : Value ) : Map< Key , Value >
}

declare class Map< Key , Value > {
	clear(): void
	delete( key : Key ) : boolean
	forEach< Context = any >( handler : ( this : Context , value : Value , key : Key , map : Map< Key , Value > ) => void , context? : Context ) : void
	get( key : Key ) : Value
	has( key : Key ) : boolean
	set( key : Key , value : Value ) : Map< Key , Value >
	size : number
}

declare class Set< Value > {
	add( value : Value ) : Set< Value >
	clear() : void
	delete( value : Value ) : boolean
	forEach< Context = any >( handler : ( this : Context , value : Value , key : Value , map : Set< Value > ) => void , context? : Context ) : void
	has( value : Value ) : boolean
	size : number
}

@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

3 participants