Close Menu
    Facebook X (Twitter) Instagram
    Nintendo-Power
    • Home
    • Top News
    • Tech
    • Nintendo
    • Downloads
    • Contact Form
    Nintendo-Power
    Home»Top News»Programming Language: TypeScript 4.4 allows codes to be code signatures
    Top News

    Programming Language: TypeScript 4.4 allows codes to be code signatures

    Edward LangleyBy Edward LangleyJuly 2, 2021No Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Programming Language: TypeScript 4.4 allows codes to be code signatures
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Microsoft has released the first beta of TypeScript 4.4. The release brings minor changes to the language level and new options for using the genre unknown In dealing with try-like modules and custom attributes.

    Type in river safety

    Typescript uses default flow analysis to determine the correct type of variables. In the following code example from the Typescript blog, the compiler uses what is called a typecard concept arg Within that if-Blocks Ten Type string To be compelled.

    function foo(arg: unknown) {
        if (typeof arg === "string") {
            // We know this is a string now.
            console.log(arg.toUpperCase());
        }
    }

    So far, the depth of the typecard code has not been explored. Therefore, a type test using a constant led to the error message: “Error! The property ‘toUpperCase’ type is not in ‘unknown’, although here the program flow is inside if-Only one ban arg Type string Reached:

    function foo(arg: unknown) {
        const argIsString = typeof arg === "string";
        if (argIsString) {
            console.log(arg.toUpperCase());
        }
    }

    TypeScript 4.4 expands the control flow analysis for TypeCard, meaning construction is now allowed. The analysis works equally well const And readonly Properties and unchanged parameters. In addition to reviews about typeof The testing of members for individual union elements also operates.

    Icons in the code

    The second linguistic addition is about access to elements via code signatures Map– Map of similar configurations via an interface:

    interface BooleanDictionary {
        [key: string]: boolean;
    }
    
    declare let myDict: BooleanDictionary;
    
    // Valid to assign boolean values
    myDict["foo"] = true;
    myDict["bar"] = false;

    Previously, the main type of access was via code signatures string And number Limited. Version 4.4 of the programming language extends the spectrum symbol-Keys:

    interface Colors {
        [sym: symbol]: number;
    }
    
    const red = Symbol("red");
    const green = Symbol("green");
    const blue = Symbol("blue");

    Likewise, access can no longer be restricted to cleanliness stringElements, but also via such string patterns `color-${string}` Proceed.

    Nothing seems to replace it

    There are also some minor innovations that can be implemented via options. So the parameter does --useUnknownInCatchVariables This means that the variables in the try-capture modules are not the default any, But as unknown Are reported. TypeScript 4.0, released almost a year ago, already allowed explicit specification any Or unknown For that catch-Path.

    When checking the code with the flag --strict The new parameter is set automatically, which can lead to incompatibility.

    Another adjustment is about custom attributes: parameter --exactOptionalPropertyTypes Ensures that the compiler allows only the explicitly specified type, not the alternative, as before undefined. For the prototype interface

    interface Person {
        name: string,
        age?: number;
    }

    Up to TypeScript 4.3, the following types of explicit work are allowed:

    const p: Person = {
        name: "Daniel",
        age: undefined,
    };

    Domestically, the property was age?: number | undefined; Are defined. The current version of the programming language, however, reacts with the error message number Direct work is allowed.

    Other innovations, such as the one modified in Typescript 4.4 --help-Can be optional Microsoft Development Blog Remove. The beta phase of Typescript 4.4 is scheduled for two months, with a final release The road should be according to the map It is set to be released on August 24th.


    (rme)

    Home page

    Edward Langley

    Edward Langley is a contributor to Nintendo-power.com, covering a wide range of topics including news, business, technology, entertainment, lifestyle and current affairs. He focuses on delivering clear, balanced and accessible reporting that helps readers stay informed about important developments and emerging trends. With an emphasis on accuracy, relevance and useful insights, Edward aims to provide engaging stories and practical information that matter to audiences in the UK and beyond.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    Acrylic Nails for the Modern Professional: Balancing Style and Practicality

    September 6, 2024

    The Majestic Journey of the African Spurred Tortoise: A Guide to Care and Habitat

    September 2, 2024

    Choosing Between a Russian and a Greek Tortoise: What You Need to Know

    June 21, 2024
    Leave A Reply Cancel Reply

    Navigate
    • Home
    • Top News
    • Tech
    • Nintendo
    • Downloads
    • Contact Form
    Pages
    • About Us
    • Contact Us
    • DMCA
    • Editorial Policy
    • Privacy Policy
    • Nintendo Power – Latest Gaming News, Reviews & Retro Updates
    Recent
    • Xbox Free Play Days: GTA Online, Planet Zoo and Dragon Ball Xenoverse 2 Headline Weekend Gaming Line-up
    • Windows 11 July Update: Five New Features UK Users Should Try
    • Farnborough Airshow Set for Take-Off Despite High-Profile Absences
    • Games Done Quick Reveals Flame Fatales 2026 Schedule Supporting Malala Fund
    • 17,000 Brain Scans Reveal Unexpected Ethnic Differences in Alzheimer’s Disease Biology
    • About Us
    • Contact Us
    • DMCA
    • Editorial Policy
    • Privacy Policy
    • Nintendo Power – Latest Gaming News, Reviews & Retro Updates
    © 2026 Nintendo Power. All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.