0

Support there is some value:

let value: string | null;

then somewhere along the way I'm certain that it's never null. But there is a function that expects a non-nullable type:

function my_func(arg: string){}

How do I tell TypeScript that my value is alright for it?

my_func(value);
// Argument of type 'string | null' is not assignable 
// to parameter of type 'string'

kolypto
  • 31,774
  • 17
  • 105
  • 99
  • I know it's a noob question and it has an answer elsewhere, but that question is not google-friendly for people looking to solve a specific problem. This one is. – kolypto Sep 25 '21 at 23:37

1 Answers1

1

Simply use !:

my_func(value!);
kolypto
  • 31,774
  • 17
  • 105
  • 99