A charger may attempt to autodetect the battery type by its voltage.
Alkaline and zinc-carbon primary (non-rechargeable) cells will have a nominal voltage of 1.5V. Ni-Cad and NiMH cells will be about 1.2V at rest.
A charger will immediately detect an Alkaline cell because its voltage is too high.
I don't believe a charger can differentiate between the Ni-Cad and NiMH types reliably. They are just too close in characteristics and differ only at the terminal charging stage when they are full.
I have not seen a lithium cell in the AA format. Its nominal voltage is either 3.2V for LFP, or 3.6V for other types, NMC, NCA, etc...
I have a lithium charger that will attempt to detect whether an 18650-format cell is LFP or NMC/NCA. I guess it can watch how the cell voltage behaves under charge.
An LFP cell voltage when full is 3.6V. Any attempt to put more charge into it will cause the voltage to quickly rise to 3.7V, 3.8V and beyond. All lithium cells are like this. It's like trying to overfill a bottle. A full bottle cannot take another tablespoon and will overflow.
For NMC/NCA/LiPo lithium types, the full voltage is 4.2V.