The structural stability and electronic properties of the ternary intermetallic compounds NiSnM (M = Ti, Zr, Hf) and the closely related Heusler compounds Ni$_2$SnM are discussed using the results of ab initio pseudopotential total energy and band-structure calculations performed with a plane wave basis set using the conjugate gradients algorithm. The results characterize the lowest energy phase of NiSnM compounds, with a SnM rocksalt structure sublattice, as narrow gap semiconductors with indirect gaps near 0.5 eV. Two other atomic arrangements for NiSnM in the MgAgAs structure result in energetically unfavorable compounds that are metallic. The gap formation in the lowest energy structure of NiSnZr and relative stability of the three atomic arrangements are investigated within a tight-binding framework and by considering the decompositions of each ternary compound into a binary substructure plus a third element sublattice. The stabilization of the lowest energy phase of NiSnZr is found to be mainly due to the relative stability of the SnZr rocksalt substructure, while the opening of the gap induced by the addition of the symmetry-breaking Ni sublattice makes a relatively minor contribution. From analysis of structural and chemical trends, CoVSn is predicted to be a new semiconducting intermetallic in the MgAgAs structure with a 0.8 eV indirect gap.