1

So I'm new to typescript. I wanted to create very simple HelloWorld where I can pass parameter (here mentioned string) to script, but I'm unable to get it to work. Here's what I'm trying to do:

let sentence: string = process.argv[1];

console.log(sentence);

But when I try to compile it (tsc file.ts) to produce file.js file to execute it with node file.js "HelloWorld" I get following error for process

error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`. Even after I run command mentioned in Error msg. What's going on?

2 Answers 2

3

Well in typescript, you need type definitions to support functions and props. Do as its suggesting you to

npm i @types/node
Sign up to request clarification or add additional context in comments.

Comments

1

try adding a tsconfig.json file and run tsc from the same folder:

{
    "compilerOptions": {
        "module": "commonjs",
        "moduleResolution": "node",
        "target": "es5",
        "lib": ["dom", "es2017"],
        "types": ["node"],
        "skipLibCheck": true
    },
    "files": ["file.ts"]
}

By default, node_modules/@types directories would be referenced: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.