The capture-avoiding substitution code overrides that and drops the type. Hence, add it back in.
I haven't added a test, as it seems that this would largely just repeat the lines added. But it might be useful as a regression check, so happy to add one if anyone feels I should.
This is nearly trivial - but where ExprTransformer preserves the type of things it copies: https://github.com/microsoft/knossos-ksc/blob/333c2ec4ed53f2818810a902aea52b57b8f94ce3/src/python/ksc/visitors.py#L95
The capture-avoiding substitution code overrides that and drops the type. Hence, add it back in.
I haven't added a test, as it seems that this would largely just repeat the lines added. But it might be useful as a regression check, so happy to add one if anyone feels I should.