Greetings, I recently made the transition from JS to TS for improved coding practices. However, TypeScript is throwing me these errors- the Validate
function worked flawlessly in JavaScript.
Property 'user' does not exist on type '{ isValid: boolean; user: string; userLowercase: string; } | undefined'
Property 'userLowercase' does not exist on type '{ isValid: boolean; user: string; userLowercase: string; } | undefined'
Here are the relevant files:
//functions.ts
function Validate(arg) {
if (!arg) return
let query :string = arg.toString().replace(""@"", "")
let regex = /^[a-zA-Z0-9._-]+$/
let isValid = regex.test(query)
if (!isValid) return
let userLowercase :string = query.toLowerCase()
return { isValid: true, user : query, userLowercase }
}
//firstCommand.ts
import { Validate } from './functions'
class firstCommand extends Commands {
async command() {
if (!Validate(this.arg)) return
const { user, userLowercase } = Validate(this.arg)
///
}
}
I have tried searching on Google but couldn't find anyone with a similar issue. Am I possibly writing the code incorrectly? Any guidance on how to resolve this would be highly appreciated.
Thank you in advance!