How to use yup’s object.shape with typescript?

following the yup guide here you should change your code as follows: import { object, SchemaOf, string } from ‘yup’; interface BaseBootstrapSchema { APPLICATION_NAME: string; LOG_PATH: string; } const bootstrapValidationSchema: SchemaOf<BaseBootstrapSchema> = object({ LOG_PATH: string().required(“The ‘LOG_PATH’ ENV variable is required”), APPLICATION_NAME: string().required(“The ‘APPLICATION_NAME’ ENV variable is required”), }); module.exports = (schema: SchemaOf<BaseBootstrapSchema>) => new Promise((resolve, … Read more

How to ‘map’ a Tuple to another Tuple type in Typescript 3.0

You’ll need to use a mapped tuple type, which is supported in TypeScript 3.1. You can make a mapped type that has properties 0, 1, 2 and length of the correct types, like this: class Maybe<T> {} type MaybeTuple = [Maybe<string>, Maybe<number>, Maybe<boolean>]; type MaybeType<T> = T extends Maybe<infer MaybeType> ? MaybeType : never; type … Read more

How is the correct way to work with Vuex and typescript?

Vuex is perfectly compatible with typescript using these vuex imports: import {GetterTree, MutationTree, ActionTree} from “vuex” The example below shows the easiest and most complete way to use vuex in typescript. Principal store file: import Vue from ‘vue’ import Vuex from ‘vuex’ import { GetterTree, MutationTree, ActionTree } from “vuex” import MySubModule from ‘@/store/submodule’ Vue.use(Vuex) … Read more

Restricting generic types to one of several classes in Typescript

I banged my head on this for a few hours, but the solution seems obvious in retrospect. First I present the solution, then I compare it to prior approaches. (Tested in Typescript 2.6.2.) // WORKING SOLUTION: union of types with type checks class MustBeThis { method1() { } } class OrThis { method2() { } … Read more

Is there anyway to do nested Pick types in Typescript

Similar to Colins answer, but coming at it from the opposite direction. If you have an existing interface/type you need to pick apart you can use indexes: // Existing type type Tenant = { id:string; description:string; name:string; approvedUsers: Array<{ id:string; alias:string; }> } // Pick it apart type TenantManagePageQueryTenant = Pick<Tenant, ‘id’ | ‘description’ | … Read more

tech