Answer the question
In order to leave comments, you need to log in
How to add a new property to the types of the included library?
Connected to the firebase project, added
firebase.getCurrentUser = () => new Promise((resolve, reject) => {
const unsubscribe = firebase.auth().onAuthStateChanged((user) => {
unsubscribe();
resolve(user);
}, reject);
});
Answer the question
In order to leave comments, you need to log in
https://www.typescriptlang.org/docs/handbook/decla...
Create a .d.ts file at the root with a name that doesn't match other files (so-called free declaration) and expand the namespace:
import 'firebase'; // нужно, чтоб не перетирать модуль, а мержить
declare module 'firebase' {
namespace firebase {
export const getCurrentUser: () => Promise<User>; // User тоже надо заимпортить
}
}
Basically a bad idea. First, it is not necessary to reforge a completely specific module into a "divine object" (see patterns, anti-patterns, SRP, etc.). Secondly, 'firebase' has its own documentation, and suddenly a method appears bypassing this documentation, the project will become more difficult for other developers to understand - even if they suddenly get around to describing their inserts, the documentation will turn out to be scattered across resources. Thirdly, the library may have its own method with the same name, and this is the most difficult case, there is no need to even explain here.
Maybe there are some more points, but the text field is too narrow to write from here..
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question