TS18049

'match' is possibly 'null' or 'undefined'.

Broken Code ❌

const team_slug = owner[0];
console.log('Responsible Team:', team_slug);
 
const regex = /@([^/]+)/;
const match = team_slug?.match(regex);
 
const org = match[1];

This error occurs because match can return null if no match is found, and accessing match[1] would result in a runtime error if null.

Fixed Code ✔️

You can fix this by safely checking if match is not null before trying to access its values:

const team_slug = owner[0];
console.log('Responsible Team:', team_slug);
 
const regex = /@([^/]+)/;
const match = team_slug?.match(regex);
 
if (match) {
  const org = match[1];
  console.log('Organization:', org);
} else {
  console.log('No match found.');
}