You don't show where updateSource
is being called, but I'm going to take a guess and assume that this T extends "object" | "array"
means you're passing in the string from typeof(myObject)
? If that's the case, an array will just return object
, not array. If you're only trying to distinguish between an actual object and an array, just pass in the boolean returned from Array.isArray
. If you really want to stick with the strings, and just make sure that T
fits the case that you have now, you can do Array.isArray(myObject) ? "array" : "object"
.