I think I do not understand, why am I getting Promise in return? I need to create object. Both options to return a value from promise do not work.
Why is it so? What am I missing?
Solution: create variable inside t().then(res=>{const myVar = {...}})
// a.js
exports.t = (key, lang, props) => {
return i18next.changeLanguage(lang).then(t => {
return t(key, props);
});
};
// b.js
import {t} from './a.js'
const myVar = {
a: "a",
b: "b",
c: (()=>{
switch (template) {
case 'a':
// Promise should return value here from t();
default:
break;
}
})(),
d: (async () => {
switch (template) {
case 'a':
// Not working, returns Promise... Why?
return await t('email.Registration Confirmation', lng);
default:
break;
}
})(),
e: (()=>{
switch (template) {
case 'a':
// Not working, returns Promise... Why?
return t('email.Registration Confirmation', lng).then(res => {
return res;
});
default:
break;
}
})()
}
Is it possible at all, that JavaScript waits for that Promise to be resolved, and then finishes creating an object?