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?
const port: Number = parseInt(<string>process.env.PORT, 10) || 3000
This solved it. I think it's called Type Assertion
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With