Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
No overload matches this call. The last overload gave the following error in typescript

i wrote the code about encrypt the string that pass in function cryto with file .env but the appear the error line i don't know what that means. i config values in .env file with environment and export default them and use in the case need them but error line show "No overload matches this call. The last overload gave the following error.

    Argument of type 'string | undefined' is not assignable to parameter of type 'WithImplicitCoercion<string> | { [Symbol.toPrimitive](hint: "string"): string; }'.
      Type 'undefined' is not assignable to type 'WithImplicitCoercion<string> | { [Symbol.toPrimitive](hint: "string"): string; }"

like this.

import { randomBytes, createCipheriv, createDecipheriv } from "crypto";
import environment from "../environment";
const ENCRYPTION_KEY = environment.encrypt_Key;
// const enc = "klyH2NOdPmmFPtdCAHIIGgjMowUUd69P";
const IV_LENGTH = 16;

export const encrypt = async (text: string) => {
  try {
    let iv = randomBytes(IV_LENGTH);
    let cipher = createCipheriv("aes-256-cbc", Buffer.from(ENCRYPTION_KEY), iv);
    let encrypted = Buffer.concat([cipher.update(text), cipher.final()]);

    return `${iv.toString("hex")}:${encrypted.toString("hex")}`;
  } catch (e) {
    console.error(e);
  }
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Most likely, your environment is defined in such a way that it either returns string or undefined for a key. One way to handle is to check that and throw error like this:

export const encrypt = async (text: string) => {
  // check if ENCRYPTION_KEY is set
  if(!ENCRYPTION_KEY) {
     throw new Error("encrypt_Key is not set");
  }

  try {
    let iv = randomBytes(IV_LENGTH);
    let cipher = createCipheriv("aes-256-cbc", Buffer.from(ENCRYPTION_KEY), iv);
    let encrypted = Buffer.concat([cipher.update(text), cipher.final()]);

    return `${iv.toString("hex")}:${encrypted.toString("hex")}`;
  } catch (e) {
    console.error(e);
  }
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!