QGIS 3.16.5 seems to crash when I use the following code block in the QGIS console.
However, there seems to be no issue at all when clicking through the same options using the GUI. The TIN interpolator works as expected when plugging-in through the GUI.
I have gone through the answers Calling interpolation plugin from Python console of QGIS and Interpolation (TIN) from Python Console in QGIS
import qgis.analysis
import qgis.core
file_path = 'D:/codebase'
pathToFile = f"{file_path}/gpd_df.shp"
layer = QgsVectorLayer(pathToFile, 'input','ogr')
layer_data = QgsInterpolator.LayerData()
layer_data.vectorLayer = layer
layer_data.zCoordInterpolation=False
index = layer.fields().indexFromName("altitude")
layer_data.interpolationAttribute = index
layer_data.sourceType = QgsInterpolator.SourcePoints
interpolation_method = QgsTinInterpolator.Linear
tin_interpolator = QgsTinInterpolator([layer_data], interpolation_method)
export_path = "D:/codebase/test.tif"
also tried export_path = "D:/codebase/test.asc"
rect = layer.extent()
res = 10
ncol = int( ( rect.xMaximum() - rect.xMinimum() ) / res )
nrows = int( (rect.yMaximum() - rect.yMinimum() ) / res)
output = QgsGridFileWriter(tin_interpolator, export_path, rect, ncol, nrows)
output.writeFile()
iface.addRasterLayer(export_path, "output")
gpd_df.shp (which loads as expected when used through GUI) file looks like the following table in the image attached.

