#Why does return []; in a function have a return type of never[]?

7 messages · Page 1 of 1 (latest)

dusty folio
#

See the attached screenshot. Here is my code:

import {
  EncounterableMonsterGirlName,
  NonEncounterableMonsterGirlName,
} from '../monster-girl-names';

export const getSceneSeenStatus = (
  monsterGirlName:
    | EncounterableMonsterGirlName
    | NonEncounterableMonsterGirlName
) => {
  return [];
};

The return type of this getSceneSeenStatus function is never[]. Why isn't it [] or any[] or unknown[] instead?

I am using tsc Version 4.8.4.

eternal belfry
surreal epoch
#

[] means an empty array
and an empty array will never be a string[] since there are no string in the array, because its empty

#

to that for every type possible, you end up with never[]

#

which isn't that big of a deal, just cast [] to the right return type

dusty folio
#

ah, makes sense

#

Thank you