```ts
export function turnCostRoute(grid: number[][], stepCost: number, turnCost: number): number {
  if (grid.length === 0 || grid.some(row => row.length !== grid[0].length)) {
    throw new Error("Grid must be non-empty and rectangular.");
  }
  if (!grid.every(row => row.every(cell => cell === 0 || cell === 1))) {
    throw new Error("Grid cells must be either 0 or 1.");
  }
  if (stepCost <= 0 || !Number.isInteger(stepCost)) {
    throw new Error("Step cost must be a positive integer.");
  }
  if (turnCost < 0 || !Number.isInteger(turnCost)) {
    throw new Error("Turn cost must be a non-negative integer.");
  }

  const numRows = grid.length;
  const numCols = grid[0].length;

  if (grid[0][0] === 1 || grid[numRows - 1][numCols - 1] === 1) {
    return -1;
  }
  if (numRows === 1 && numCols === 1) {
    return 0;
  }

  const directions = [
    [0, 1], // right
    [1, 0], // down
    [0, -1], // left
    [-1, 0] // up
  ];

  interface State {
    row: number;
    col: number;
    direction: number; // index into directions array
    cost: number;
  }

  const isValid = (row: number, col: number): boolean => {
    return row >= 0 && row < numRows && col >= 0 && col < numCols && grid[row][col] === 0;
  };

  const queue: State[] = [
    { row: 0, col: 0, direction: -1, cost: 0 } // -1 indicates no previous move
  ];

  const visited = new Set<string>();

  while (queue.length > 0) {
    const { row, col, direction, cost } = queue.shift()!;
    const key = `${row},${col},${direction}`;
    if (visited.has(key)) continue;
    visited.add(key);

    if (row === numRows - 1 && col === numCols - 1) {
      return cost;
    }

    for (let i = 0; i < directions.length; i++) {
      const [dRow, dCol] = directions[i];
      const nextRow = row + dRow;
      const nextCol = col + dCol;

      if (!isValid(nextRow, nextCol)) continue;

      const newCost = cost + stepCost + (direction !== -1 && i !== direction ? turnCost : 0);
      queue.push({ row: nextRow, col: nextCol, direction: i, cost: newCost });
    }
  }

  return -1;
}
```