via ProductRepository:
$product = $this->productRepository->get($product['sku']);
$stockItem = $this->stockRegistry->getStockItem($product->getId());
$stockItem->setIsInStock(true);
$this->stockRegistry->updateStockItemBySku($product->getSku(), $stockItem);
$product->setTypeId('configurable');
$this->productRepository->save($product);
StockItem is not updated!! Product is saved. But Stock is not (or rolled back). If comment the last line in code above (product saving) - stock will updated ok.
via Model \Magento\Catalog\Model\Product:
$productModel = $this->productFactory->create();
$product = $productModel->loadByAttribute('sku', $product['sku']);
$stockItem = $this->stockRegistry->getStockItem($product->getId());
$stockItem->setIsInStock(true);
$this->stockRegistry->updateStockItemBySku($product->getSku(), $stockItem);
$product->setTypeId('configurable');
$product->save($product);
Both - StockItem and Product updated!
How to update stock and update product in Magento way?