My code is:
const port: Number = process.env.PORT || 3000;
[ts]
Type 'string | 3000' is not assignable to type 'Number'.
Type 'string' is not assignable to type 'Number'.
I tried
const port: Number = parseInt(process.env.PORT, 10) || 3000;
But it gives me another error:
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
(property) NodeJS.Process.env: NodeJS.ProcessEnv
What am I doing wrong?
parseInt, which may be undefined but must be a string. I think you wantparseInt(process.env.PORT || '3000', 10).