I'm currently converting a piece of code to TypeScript and running into a few type issues with yup
types. I've tried multiple ways and referenced yup
's documentation on TypeScript support to tackle this issue to no avail.
https://github.com/jquense/yup/blob/master/docs/typescript.md
Here is a sample of my code:
import { object, Asserts, string } from 'yup';
interface BaseBootstrapSchema {
APPLICATION_NAME: string;
LOG_PATH: string;
}
const bootstrapValidationSchema = object<BaseBootstrapSchema>().shape({ // error 1 here
LOG_PATH: string().required("The 'LOG_PATH' ENV variable is required"),
APPLICATION_NAME: string().required("The 'APPLICATION_NAME' ENV variable is required"),
});
interface BootstrapSchema extends Asserts<typeof bootstrapValidationSchema> {}
module.exports = (schema: BootstrapSchema) =>
new Promise((resolve, reject) =>
schema
.validate(process.env, { abortEarly: false }) // error 2 here
.then(() => resolve(true))
.catch((error: any) => {
if (error.errors.length > 1) {
reject(new Error(`${error.message},\n${error.errors.join(',\n')}`));
} else {
reject(new Error(error.message));
}
})
);
I get the following errors:
Error 1:
Type 'BaseBootstrapSchema' does not satisfy the constraint 'Record<string, AnySchema<any, any, any> | Reference | Lazy<any, any>>'. Index signature is missing in type 'BaseBootstrapSchema'.
Error 2:
Property 'validate' does not exist on type 'BootstrapSchema'.
I'm tried a few ways to rectify this issue but none really work.
Assistance appreciated.