Typewriters without some form of silencing are clattery things, and many suffer from the original foam disintegrating with time, and failing to do its job. The particles of the old foam also get into the works.
The solution is 1/16" thick closed cell, self-adhesive neoprene. It's a perfect replacement. I bought a foot square piece on eBay from seller adrian22305.
First photograph the part with the old foam still in it. The following example is from a 1959 Oliver Courier typewriter.
This gives you clues as to how far the replacement needs to fit so it doesn't foul any of the mechanism. Pay attention to any bare spots for this reason, particularly when working on parts in the sides of a typewriter's bodywork.
Next you remove the old foam. This is usually easy, as some can be brushed out or rubbed off. You can remove the glue that held the foam on with gentle scraping. Make a paper template to fit the area where the foam used to be. Use a pencil to transfer tricky areas like curves onto the paper before you cut it, and check your photographs for special areas that need to be cut out.
Turn the template the other way up, and use a fine Sharpie marker to transfer the template shape onto the paper backing of the neoprene. Cut out the shape following the marks, then check the fit. If extra cutting is needed to allow for the thickness of the neoprene, you'll be able to see this. Once the neoprene fits, remove the backing and set the new material in place.
Reassemble the typewriter, and enjoy the more refined sound. Happy typing!