A good method will involve all three modes, in combination with each other. The mode will depend on the objective of the demo and the size of the code. If the students are not touch typists, there's going to be some, possibly hard to spot, errors, and entering a 50 line code segment will take a significant portion of the available time.
For small, basic sections of code, having a type-along can work. Especially if you're inserting segments, and changing parts, as the design evolves. You won't want to have them constantly typing the same basic parts every time you do a type-along session, however.
In some cases, you might want to do a larger demo of the small code. First is them watching you do the work, as you demonstrate some concept. Second, you do a type-along demo, where they help demonstrate the concept just learned from the solo demo, as the class writes a second piece collectively. Lastly, as lab, they apply the concept to a third code, following a problem statement you give them, but they develop the solution themselves with minimal guidance from you.
For moderate sized code, have the skeleton pre-typed, and available for download before the lecture, then work through the section that is the target of the class session. Concepts that have already been mastered need not be retyped each session.
When you get to the point where you are re-factoring code, or combining previous sections with new content, you can have that available for download as well, but do the demo without them typing. While doing the demo, you should also limit your typing. Have what you want to type ready, and to a copy/paste of the proper blocks. They presumably will be familiar with the concepts in the smaller sections, and the the objective is combining them to create a larger concept.
The last version is to distribute completed code for them to analyze, except that it's not fully working code - it's broken. The task is to find the error using the clues the compiler/interpreter gives. Of course, that means trying to design broken code that fails the way you want it to.