Yup: Type 'StringSchema<string>' is not assignable to type 'Ref | Schema<Sample>'.

In Yup, using Typescript string literals in a shape definition will currently give a generic error message:

Type 'StringSchema<string>' is not assignable to type 'Ref | Schema<Sample>'.

For example, trying to use the following interface will produce the above error:

interface Sample {
  allowed: 'foo' | 'bar';
};

const shape = yup.object().shape<Sample>({
  allowed: yup.string().required(),
});

Yup’s typing doesn’t currently support this, until then, a conditional utility type can solve the issue:

type YupShape<T> = {
  [K in keyof T]: T[K] extends string ? string : T[K];
}

const shape = yup.object().shape<YupShape<Sample>>(...);

You will lose type checking for the literal values, but keep your sanity until it gets fixed upstream.