Typescript: Mapa, Establecer ... en el objetivo ES5

Creado en 28 may. 2015  ·  3Comentarios  ·  Fuente: microsoft/TypeScript

Después de actualizar el compilador de mecanografiado de la versión 1.4.1 a la 1.5.0 beta, el código fuente incluido en mi proyecto se convirtió en un registro de errores como "No se encuentra el mapa".
Por lo tanto, investigué este problema y llegué a una conclusión. El lib.d.ts pasó a no contener definiciones de mapas y conjuntos, excepto que se seleccionó ES6 en tsconfig.json.

En realidad, Map and Set es una especificación de ES6. Es natural que no podamos usar Map and Set en el proyecto dirigido a ES5 o inferior.
Pero podríamos usar Map and Set incluso si selecciono ES5 como objetivo antes del mecanografiado 1.4.1.
Sé que hacer que esté habilitado para usar Map and Set en el proyecto que está hecho para ES5 conlleva un riesgo.
Porque hay algunos navegadores que no son compatibles con Map and Set.

Sin embargo, creo que es mejor hacer alguna propiedad de la configuración que sea para cambiar para usar estas definiciones o no. ¿No te parece?

Question

Comentario más útil

@LimeStreem eliminamos algunos tipos específicos de IE de la biblioteca en 1.5.0-beta. simplemente puede definir el tipo en uno de sus archivos como:

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>;
}

Todos 3 comentarios

@LimeStreem eliminamos algunos tipos específicos de IE de la biblioteca en 1.5.0-beta. simplemente puede definir el tipo en uno de sus archivos como:

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>;
}

¡Guau, te agradezco que escribas este fragmento de código! :risa:
¡Me pregunto si este problema ayudará a muchos usuarios de mecanografiado!

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
}
¿Fue útil esta página
0 / 5 - 0 calificaciones

Temas relacionados

manekinekko picture manekinekko  ·  3Comentarios

siddjain picture siddjain  ·  3Comentarios

uber5001 picture uber5001  ·  3Comentarios

jbondc picture jbondc  ·  3Comentarios

MartynasZilinskas picture MartynasZilinskas  ·  3Comentarios