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,'🚗'); } 
7
  • there is no ":" in javascript, it should be function placeEmoticon(message){return message.replace(/\bcar\b/g,'🚗');} Commented Oct 14, 2018 at 17:40
  • hi, thanks peter, but how javascript knows that parameter is a string type ? Commented Oct 14, 2018 at 17:52
  • this function placeEmoticon(message : string): string { return message.replace(/\bcar\b/g,'🚗'); } is in typescript typescriptlang.org/docs/handbook/functions.html, check this: stackoverflow.com/questions/12364614/… Commented Oct 14, 2018 at 17:56
  • Thanks so much, can you post this as an answer so I can accept it ? Commented Oct 14, 2018 at 17:58
  • I have this last error placeEmoticon is not defined at exports.createdMessage.functions.database.ref.onCreate Commented Oct 14, 2018 at 18:00

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.