0

I'm following the video of Doug on youtube to change a message with functions, I'm doing it in javascript, I have installed flow lenguage script since I had an error about 'types' can only be applied to ts files , now, that error is gone, but when I try to deploy my function I get this error message.

enter image description here

This is my code

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

    exports.createdMessage = functions.database.ref('/users/messages/{messageId}').onCreate((snapshot,context)=>{

            const messageID = context.params.messageId;
            console.log('Message ${messageID}');

            const messageData = snapshot.val();
            const message = placeEmoticon(messageData.message);


            return snapshot.ref.update({message:message});

    });

    function placeEmoticon(message : string): string {

        return message.replace(/\bcar\b/g,'');

    }
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
Todd
  • 179
  • 15
  • there is no ":" in javascript, it should be `function placeEmoticon(message){return message.replace(/\bcar\b/g,'');}` – Peter Haddad Oct 14 '18 at 17:40
  • hi, thanks peter, but how javascript knows that parameter is a string type ? – Todd Oct 14 '18 at 17:52
  • this `function placeEmoticon(message : string): string { return message.replace(/\bcar\b/g,''); }` is in typescript https://www.typescriptlang.org/docs/handbook/functions.html, check this: https://stackoverflow.com/questions/12364614/how-does-javascript-know-what-type-a-variable-is – Peter Haddad Oct 14 '18 at 17:56
  • Thanks so much, can you post this as an answer so I can accept it ? – Todd Oct 14 '18 at 17:58
  • I have this last error placeEmoticon is not defined at exports.createdMessage.functions.database.ref.onCreate – Todd Oct 14 '18 at 18:00
  • I just fixed it, thanks so much peter ! – Todd Oct 14 '18 at 18:04
  • no problem goodluck! – Peter Haddad Oct 14 '18 at 18:05

1 Answers1

2

Change this:

function placeEmoticon(message : string): string {

    return message.replace(/\bcar\b/g,'');

}

This is written in typescript where you can specify the return type and the type of the parameters. https://www.typescriptlang.org/docs/handbook/functions.html

into this:

function placeEmoticon(message) {

    return message.replace(/\bcar\b/g,'');

}

Since you are using javascript.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134