Can't get setBlockType command to work

I’m adding some keyboard shortcuts using the keymap function from prosemirror-keymap. I have a text with 10 paragraphs to test, and I select the 1st paragraph only, then tried with 2 paragraphs. This is the code:

keymap({'Ctrl-Shift-/': setBlock('code_block')});

const setBlock = (
  nodeName: string
) => (state: EditorState, dispatch?: (tr: Transaction) => void) => {
  const { schema } = state;
  const nodeType = schema?.nodes[nodeName];
  return setBlockType(nodeType)(state, dispatch);
};

So, that is not working. This is the error I get:

Uncaught RangeError: Type given to setBlockType should be a textblock
    at Transaction3.Transform.setBlockType (structure.js:117:32)
    at commands.js:464:37
    at key-binding-plugin.ts:24:23
    at Plugin10.<anonymous> (keymap.js:93:23)
    at input.js:119:50
    at EditorView5.someProp (index.js:231:40)
    at editHandlers.keydown (input.js:119:19)
    at HTMLDivElement.view.dom.addEventListener.view.eventHandlers.<computed> (input.js:46:9)

Then I also tested with (1 and 3 are numbers just to test):

dispatch(state.tr.setBlockType(1, 3, nodeType));

That didn’t work too, with the same error as before.

Any idea or guidance on what can be wrong here?

I just fixed it. I realized that depending on the nodeType, you need to use setBlockType or wrapIn.