'How to let TypeScript autocast from custom type

I am building a wrapper for a ioredis transaction. Per the docs a transaction look like this:

redis
  .multi()
  .set('key1', 'hello')
  .set('key2', 'world')
  .exec()

to make it more reusable, I made a wrapper to genereate a transaction. ValueType is the default type for values passed to .set() and is defined by the library: type ValueType = string | Buffer | number | any[]

const setMultiple = async (items: [string, ValueType][]) => {
   // impl
}

Now when I call this function using some string values, TypeScript says the types don't match, when string is clearly allowed per ValueType:

const commands = [
    ['key1', 'hello'],
    ['key2', 'world'],
];

const result = Redis.setMultiple(commands);
// err: Argument of type 'string[][]' is not assignable to parameter of type '[string, ValueType][]'

How can I make TypeScript shut up here since this is clearly allowed. string is just wrapped in ValueType. I know I can just force cast commands by passing commands as [string, ValueType][] but it should automatically understand these are correct values right?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source