Skip to content

Suggestion: Offer us some frequent JS class types and functions #1174

Closed

Description

It seems that we now have turple, string, number……But it would be better if we could have List, Stack, Queue,Dictionary<K,V> and other very useful and frequent class types like those in C#, I hope Microsoft can offer us such class types packaged in the install exe file directly, so that when we upgraded to the latest version, we can use them instead of writing them again and again.

Also it would be better if Microsoft can offer us some frequent libraries to be downloaded with many useful functions, something like:

  1. Serialization/Deserialization functions:
    function Serialize(object:T):string
    {
    return JSON.stringify(object);
    }
    function Deserialize(JsonString:string):T
    {
    var object:T = JSON.parse(JsonString);
    return object;
    }
    The codes below are ONLY samples, so Microsoft can invent a compatible way to cope with almost all kinds of browsers such as from IE7……

  2. Logger: It should include three levels (Error, Warning, Info) with different kinds of colors (Red, Yellow, Blue), for browser's scripts' debugging and do some special logging. And what's more, the Logger should have some global settings that allow us whether to show these logs or not according to the levels' setting.

Activity

  1. DanielRosenwasser commented on Nov 16, 2014

    @DanielRosenwasser
    Member

    It is not useful to focus our resources on something like this when you can just tap into the existing JavaScript/TypeScript ecosystem. If you need to support older browsers, use one of the many available polyfills.

  2. danquirk commented on Nov 17, 2014

    @danquirk
    Member
  3. danquirk commented on Nov 19, 2014

    @danquirk
    Member

    A JavaScript array can easily behave as a list. The built in methods allow for things like pushing onto the list while built in functions and combinators from libraries like underscore let you do the various find/take/indexOf type operations.

    A JavaScript object is already a dictionary.

    var x = {};
    x["myKey"] = "myValue";

    With a TypeScript interface for safety (underscore.d.ts has this sort of definition):

    interface Dictionary<T> {
        [key: string]: T;
    }
    var x: Dictionary<string> = {};
    x["myKey"] = 1; // error, expects string values

    Tuples are simply array literals with a tuple type annotation, there's no need for an additional type definition:

    var x: [string, number] = ["hello", 1];

    There're numerous existing JS libraries for logging to suit a variety of different purposes. There's not some unique value we can deliver by shipping our own implementation.

  4. danquirk commented on Nov 24, 2014

    @danquirk
    Member

    Correct, because JavaScript doesn't lack fully featured libraries but it does lack the properties associated with stronger typing.

  5. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraints

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions