Reputation: 405
I have this asynchronous function and am trying to return an object or null.
But I get an error in defining the type.
How to define this data type?
const checkIsValidConnection = async (number: string): Promise<string | null> => {
const defaultConnection = await GetDefaultConnection();
const wbot = getWbot(defaultConnection.id);
const contactId = await wbot.getNumberId(`${number}`);
return contactId;
};
export default checkIsValidConnection;
Type 'ContactId | null' is not assignable to type 'string | null'.
Type 'ContactId' is not assignable to type 'string'.
Upvotes: 1
Views: 92
Reputation: 551
I believe you're working with https://github.com/pedroslopez/whatsapp-web.js/blob/master/index.d.ts
which indicates WAWEBJS.ContactID
to be an interface of the following.
interface ContactId { server: string, user: string, _serialized: string}
You should update the return type of your promise to either this interface
or stick to the WAWEBJS.ContactID
Upvotes: 2