Skip to content

Deprecated str.substr warning #58720

Closed
@jdarwood007

Description

@jdarwood007

I receive the following warning in Visual Studio

TS6387	(JS) The signature '(from: number, length?: number): string' of 'str.substr' is deprecated.	signalr.js	380		

The affected code seems to be:

return str.substr(0, str.length - 1);

function formatArrayBuffer(data) {
    const view = new Uint8Array(data);
    // Uint8Array.map only supports returning another Uint8Array?
    let str = "";
    view.forEach((num) => {
        const pad = num < 16 ? "0" : "";
        str += `0x${pad}${num.toString(16)} `;
    });
    // Trim of trailing space.
    return str.substr(0, str.length - 1);
}

Seems to be simple, use str.substring instead.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions