FAQ: Functions - Explicit Return Types

This community-built FAQ covers the “Explicit Return Types” exercise from the lesson “Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn TypeScript

FAQs on the exercise Explicit Return Types

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I couldn´t find where it said that f9 was the problematic function!

2 Likes

I’m not sure this is working correctly. When I run it, I get this error:

$ node index.ts 
(node:97) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/home/ccuser/workspace/typescript-functions-explicit-return-types/index.ts:1
import {getUserChoice,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12} from './resources'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
1 Like

In order to get a hint about where the problematic function is, you need to run the tsc command on the bash.
It’s been some time since you asked but I hope you find my answer useful.

Have a great coding!

Hello! According to this question, it seems to be a little bug in TypeScript.

Perhaps at the time you are reading this, Codecademy fixed the exercise because it appears to be working fine…

I’m getting the same error. Not sure what I should do by now.

I can’t see which function has the problem, tsc error says:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory internal/bootstrap/switches/does_own_process_state.js:128 cachedCwd = rawMethods.cwd(); ^ Error: ENOENT: no such file or directory, uv_cwd at process.wrappedCwd [as cwd] (internal/bootstrap/switches/does_own_process_state.js:128:26) at /usr/lib/node_modules/typescript/lib/tsc.js:4495:79 at Object.getCurrentDirectory (/usr/lib/node_modules/typescript/lib/tsc.js:1323:25) at executeCommandLineWorker (/usr/lib/node_modules/typescript/lib/tsc.js:97448:51) at Object.executeCommandLine (/usr/lib/node_modules/typescript/lib/tsc.js:97530:20) at Object.<anonymous> (/usr/lib/node_modules/typescript/lib/tsc.js:97818:4) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) { errno: -2, code: 'ENOENT', syscall: 'uv_cwd' }

I have the same issue. Not sure how the error could help me find out which function is problematic. Here’s what I see in the console:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
internal/bootstrap/switches/does_own_process_state.js:128
  cachedCwd = rawMethods.cwd();
                         ^

Error: ENOENT: no such file or directory, uv_cwd
    at process.wrappedCwd [as cwd] (internal/bootstrap/switches/does_own_process_state.js:128:26)
    at /usr/lib/node_modules/typescript/lib/tsc.js:4495:79
    at Object.getCurrentDirectory (/usr/lib/node_modules/typescript/lib/tsc.js:1323:25)
    at executeCommandLineWorker (/usr/lib/node_modules/typescript/lib/tsc.js:97448:51)
    at Object.executeCommandLine (/usr/lib/node_modules/typescript/lib/tsc.js:97530:20)
    at Object.<anonymous> (/usr/lib/node_modules/typescript/lib/tsc.js:97818:4)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'uv_cwd'
}

Dear Course planner/creator,

Please assist us by looking into this issue if possible?

$ tsc
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
internal/bootstrap/switches/does_own_process_state.js:128
  cachedCwd = rawMethods.cwd();
                         ^

Error: ENOENT: no such file or directory, uv_cwd
    at process.wrappedCwd [as cwd] (internal/bootstrap/switches/does_own_process_state.js:128:26)
    at /usr/lib/node_modules/typescript/lib/tsc.js:4495:79
    at Object.getCurrentDirectory (/usr/lib/node_modules/typescript/lib/tsc.js:1323:25)
    at executeCommandLineWorker (/usr/lib/node_modules/typescript/lib/tsc.js:97448:51)
    at Object.executeCommandLine (/usr/lib/node_modules/typescript/lib/tsc.js:97530:20)
    at Object.<anonymous> (/usr/lib/node_modules/typescript/lib/tsc.js:97818:4)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'uv_cwd'
}

similar error – Nov 2022

$ node index.ts
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
node:internal/bootstrap/switches/does_own_process_state:126
    cachedCwd = rawMethods.cwd();
                           ^

Error: ENOENT: no such file or directory, uv_cwd
    at process.wrappedCwd [as cwd] (node:internal/bootstrap/switches/does_own_process_state:126:28)
    at node:path:1082:24
    at Object.resolve (node:path:1096:39)
    at resolveMainPath (node:internal/modules/run_main:19:40)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:71:24)
    at node:internal/main/run_main_module:17:47 {
  errno: -2,
  code: 'ENOENT',
  syscall: 'uv_cwd'
}

A few questions:

  • Have you tried resetting the exercise?

  • What exactly are you typing in the terminal?

  • Can you copy the code (after you have added the console statement of Step 1) in index.ts and paste it here on the forums?

  • If you enter ls in the terminal, what files do you see?

Hello, as of 12/22/22 this is still happening at least for me, the exercise does not appear to be working. I am getting the same error that @pudpark reported in April

The exercise seems to be working for me.

In pupark’s screenshot, node index.ts has been entered in the terminal. Instead it should have been node index.js as indicated in the hints as well. If that doesn’t help, then consider the questions I asked in the post above yours.

1 Like

You should run index.js, not index.ts.

1 Like

Same error with running index.js

$ node index.js
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
node:internal/bootstrap/switches/does_own_process_state:126
cachedCwd = rawMethods.cwd();
^

Error: ENOENT: no such file or directory, uv_cwd
at process.wrappedCwd [as cwd] (node:internal/bootstrap/switches/does_own_process_state:126:28)
at node:path:1082:24
at Object.resolve (node:path:1096:39)
at resolveMainPath (node:internal/modules/run_main:19:40)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:71:24)
at node:internal/main/run_main_module:17:47 {
errno: -2,
code: ‘ENOENT’,
syscall: ‘uv_cwd’
}
$

  • Have you tried resetting the exercise?

  • What exactly are you typing in the terminal?

  • Can you copy the code (after you have added the console statement of Step 1) in index.ts and paste it here on the forums?

  • If you enter ls in the terminal, what files do you see?

it seems to be a problem with “Bash”. I was able to complete the exercise by opening another Bash window and running tsc in it.

I reloaded the window, typed in tsc, and it worked.

1 Like


some issues with the bash, I was force to reload the entire task to get the answer

Thanks! Doesn’t look like that for me.