In my experience, this is a problem that appeared after I upgraded from Mojave (10.14) to Monterey (12). In Mojave, I would get sensible file types and icons for my older files with type/creator codes and no extensions. But now, even when the Mac understands the document type based on the type/creator codes, it displays the wrong icon. And even then, it displays a different incorrect icon for different files, with seemingly no reason:
But to answer your question about how to access type/creator codes, Apple actually provides a command line tool for this called GetFileInfo:
> GetFileInfo Initial\ letter\ to\ Prof\ Smyth
file: "/Users/me/Documents/Correspondence/Letters/Initial letter to Prof Smyth"
type: "WPD3"
creator: "WPC2"
attributes: avbstclInmedz
created: 05/18/2002 13:08:02
modified: 05/18/2002 13:08:02
You can get just the type code or just the creator code:
> GetFileInfo -t Initial\ letter\ to\ Prof\ Smyth
"WPD3"
> GetFileInfo -c Initial\ letter\ to\ Prof\ Smyth
"WPC2"
So it would be relatively simple to create a script (e.g. in AppleScript) that you could drop a file or files on, and it would extract the type & creator codes, look up the document type associated with them, and append the appropriate extension to the file.
You would have to manually create this lookup table, and there is no ‘master list’ to get the type/creator codes from. But there are some lists already on the web that most likely cover any file you’re likely to come across. And any files you have not on these lists, you could do a search and find out what they are. (As an aside, a lot of the creator codes can be guessed from the letters used, but some are ‘obvious’ only because they became well known, like BOBO for ClarisWorks/AppleWorks and R*ch for BBEdit.)
[Pythonmac-SIG] Discovering file type
Mac Creator and File Type codes
(As a final aside, Apple also provides the corresponding SetFile command line utility, so creating reverse script – assigning type/creator codes based on filename extensions – would also be possible.)

