Embedding numbers into strings in strict mode

Hi all,

I am trying to assign a file path to a variable in Typescript while in strict mode.
The path has numbers in it, particularly the date of creation prefixed.
The code is being executed in Node.JS.

This is the path:

const path = 'C:\\Software Development\\2020_12_21_NET_NodeJS\\NET_NodeJS_01';

error - [Octal escape sequences are not allowed in strict mode.]

My thought at that point was to break the string into elements of an array, then join the elements into the finished string.

const path_parts = [
        'C:\\Software Development\\',
     '2020_12_21_NET_NodeJS\\NET_NodeJS_01'
                   ];

const path = path_parts.join ();

error - [Numeric separators are not allowed at the end of numeric literals]

Try again:

const path_parts = [
        'C:\\Software Development',
     '\\2020',
     '_12', '_21_NET_NodeJS\\NET_NodeJS_01'
                   ];

error - [Octal escape sequences are not allowed in strict mode.]

Try again:

const path_parts = [
        'C:\\Software Development\\',
     '2020',
     '_12', '_21_NET_NodeJS\\NET_NodeJS_01'
                   ];

error - [Unexpected number]

Try again:

const path_parts = [
        'C:\\Software Development\\',
     '2020',
     '_', '12', '_21_NET_NodeJS\\NET_NodeJS_01'
                   ];

error - [Unexpected number]

Remove the first element in the array, then try again:

const path_parts = [
     '2020',
     '_12', '_21_NET_NodeJS\\NET_NodeJS_01'
                   ];

no error

Remove the trailing double-backslash in the first element
within last array, then try again:

const path_parts = [
        'C:\\Software Development',
     '2020',
     '_', '12', '_21_NET_NodeJS\\NET_NodeJS_01'
                   ];

no error

Any help would be appreciated!

I’m not familiar with the error message, but are you sure it’s being caused by that line?

Given the following in index.ts:

const greet = (msg) => { console.log(msg); };
const path = 'C:\\Software Development\\2020_12_21_NET_NodeJS\\NET_NodeJS_01';

Running the tsc command against that file produces no output.

jim@hal:~/Desktop/test$ tsc index.ts
jim@hal:~/Desktop/test$ 

Turning on strict mode produces an error about the implicit any, but nothing resembling what you are seeing:

jim@hal:~/Desktop/test$ tsc index.ts --strict

index.ts:1:16 - error TS7006: Parameter 'msg' implicitly has an 'any' type.
1 function greet(msg) {
                 ~~~
Found 1 error.

jim@hal:~/Desktop/test$ 

Could you possibly provide enough code/instructions that we can reproduce the error you are seeing.

1 Like

I am so sorry.

I did not make myself clear.

the error that I am getting is not from TypeScript,
but comes when I run the generated Javascript code in Node.JS.

No problem :slight_smile:

I’m still not seeing it.

index.ts

const path = 'C:\\Software Development\\2020_12_21_NET_NodeJS\\NET_NodeJS_01';
console.log(path);

Run tsc index.ts --strict to create index.js. This contains:

"use strict";
var path = 'C:\\Software Development\\2020_12_21_NET_NodeJS\\NET_NodeJS_01';
console.log(path);

Run that using node index.js:

jim@hal:~/Desktop/test$ node index.js
C:\Software Development\2020_12_21_NET_NodeJS\NET_NodeJS_01

Still no error.

1 Like

I managed to figure this out.

The code is being run through the eval function, and I needed to escape the escapes.

var path = 'C:\\\\Software Development\\\\2020_12_21_NET_NodeJS\\\\NET_NodeJS_01';

SILLY mistake — sorry to have bothered you.

THANKS!

1 Like