#can anyone help me with with resolving this error

65 messages · Page 1 of 1 (latest)

golden plaza
#

let myVariable :string = "Hello, TypeScript!";

console.log(myVariable);

C:\DEVIPREP\typealias.ts:49
let myVariable :string = "Hello, TypeScript!";
^

SyntaxError: Unexpected token ':'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
PS C:\DEVIPREP> ^C
PS C:\DEVIPREP> ^C
PS C:\DEVIPREP>

mental fable
#

@golden plaza you are trying to run the TS file directly

#

you need to compile the TS code into JS code first

#

then you'll be able to run it using Nodejs

golden plaza
#

i tried first with TSC

#

then with node

mental fable
#

and are you running the file emitted by tsc?

#

the JS file?

golden plaza
#

emitted ?

mental fable
#

"created"

golden plaza
#

yes

mental fable
#

when you run tsc, tsc will read your .ts files and generate corresponding .js files

#

you should then run the .js file

golden plaza
#

the problem is if i expliclty mention the annotation type it does not compile

mental fable
golden plaza
#

some other option needs to be enabled in tsconfig.json?

#

error messgae is what i posted in top

mental fable
mental fable
golden plaza
#

tsc is not runnning

#

becasue i could not see the respective codes once i do tsc in JS file

#

what next?

#

if i do not mentioned explicity the annotation type then it works fine

#

let myVariable = "Hello, TypeScript!";(works)

#

let myVariable:string = "Hello, TypeScript!";(do not work)

mental fable
#

so you're saying:

  • you have index.ts
  • you run tsc
  • it produces a file called index.js
  • then run it with node index.js
    and it throws that error?
golden plaza
#

i created index.ts,,, addded the code,, ran tsc.. do not generate

#

let myVariable:string = "Hello, TypeScript!";(

#

here is the simple code

#

if i remove the :string then it works fine

mental fable
mental fable
#

node cannot run TS code

#

what version of nodejs do you have? (node --version)

golden plaza
#

v16.15.0

golden plaza
mental fable
#

node cannot run TS code

#

run the JS file instead

#

do node ./index.js
not node ./index.ts

golden plaza
#

the js file file itself is not generated

mental fable
#

wdym? it should be

#

what does your tsconfig.json look like?

golden plaza
mental fable
#

@golden plaza that's because the generated JS file is in the dist folder

#

run node ./dist/index.js

golden plaza
#

ok

#

ran fine with JS

#

but why not with node? or we cannot run anytime?

#

i mean with .ts file

mental fable
#

because node was made to run JS, nothing else

#

TS arrived later

#

and the TS team decided they would generate JS files from the TS code and run those

#

instead of creating a separate program to run TS code

golden plaza
#

so everytime we need to run .js file and not .ts?

mental fable
#

yes

#

if you want to run TS code directly, look up ts-node, tsx, deno, or bun

golden plaza
#

ok

#

could you help me with some documentation that typescript with selenium automation?

mental fable
#

that's a different question
so probably best if you create a different help thread

#

also, have you had a look at the Selenium docs, it should be explained in great details

golden plaza
#

thanks

#

i will start a separate thead to understand more on this

#

thw post option is disabled now