I am working on a side project using TS and Firebase CLI 11.16.1
I usually use JS only. When I created my Firebase project I opted for Typescript for the functions. (Then saw it was TS transpiled to JS but nevermind)
I did the classic stuff : firebase init
Then opted for functions and Typescript instead of Javascript.
I wrote my functions without any error (in TS) in my functions/src/index.ts file.
exports.todayCode = functions.pubsub.schedule('every day at 00:01').onRun((context) => {
const fsdb = admin.firestore();
const colors = ["R", "G", "B", "Y", "P", "O"];
let code = "";
const date = formatDateWithZone(new Date(),'Europe/Paris').slice(0, 10);
//generate random code from the colors array and add it to the code string
for (let i = 0; i < 4; i++) {
code += colors[Math.floor(Math.random() * colors.length)];
}
const codeObj = {
code: code
}
//save the code in the firestore database with the date formatted YYYY-MM-DD as id
return fsdb.collection("codes").doc(date).set(codeObj);
});
I deployed using the classical firebase deploy
Then i did few changes deployed again. (changing the Timezone since I want it to run at Paris time adding new updates to the database etc)
exports.todayCode = functions.pubsub.schedule('every day at 00:01').timeZone('Europe/Paris') .onRun((context) => {
const fsdb = admin.firestore();
const colors = ["R", "G", "B", "Y", "P", "O"];
let code = "";
console.log("creating code");
const date = formatDateWithZone(new Date(),'Europe/Paris').slice(0, 10);
console.log("today date : " ,date);
//generate random code from the colors array and add it to the code string
fsdb.collection("codes").doc(date).get().then((doc: { exists: any; })=>{
if(doc.exists)
{
console.log("code existe déja !")
return true;
}
else
{
for (let i = 0; i < 4; i++) {
code += colors[Math.floor(Math.random() * colors.length)];
}
const codeObj = {
code: code,
date : new Date()
}
console.log("code created !");
//save the code in the firestore database with the date formatted YYYY-MM-DD as id
return fsdb.collection("codes").doc(date).set(codeObj);
}
});});
And deployed again. Theses changes never seemed to apply correctly. Like if the functions never updated itself. Every time I run my functions, it's still the first version.
But the deployment logs are fine, it says functions got updated and deployed.
Then I checked the function inside cloud platform and saw a hierarchy with a lib folder.
Then checked the doc and saw it was transpiled TS code to Javascript 
So my code is in src/index.ts. Cloud platform is supposed to convert it to Javascript, inside the lib folder; Inside the lib there is an index.js, then a folder with another index.js, which are supposed to be my converted code. First thing I don't understand, why is there two files ?
I checked, and the first index.js (lib/index.js) is still the first version of my code I wrote. (first block) The second one (lib/functions/src/index.ts) is my most recent code. (2nd block)
When i try to deploy using CLI, everything seem to work fine. But then when I run my functions, manually or at 00:01 it's still the first version (the code of the lib/index.js)
I tried to edit manually this lib/index.js with cloud platform and deploy, it revert back to the first version.
Am I the only one who got the issue ? My guess is : it uses the wrong functions (older) since there is one in the root of the /lib and another in lib/functions/src ...
If I can't find a way to resolve this I will try to go back to Javascript for the cloud functions and deploying again.
Don’t know why the wrong version of your code is being used when you run your functions. One thing you could try is to delete the
libdirectory and then runfirebase deployagain so This will force the Firebase CLI to transpile your TypeScript code and place the output in a new lib directory, which should contain the most recent version of your code.You can also view the logs for your functions by running the
command to get more information about the behavior.
You may also try to delete all the functions and recreate the function using
with giving typescript as your options and making sure your directories are named correctly as per the context. And deploy the function locally to verify that it is working correctly in the local environment, this can be done with firebase emulators