xxxxxxxxxx
const myObj = { a: 1, b: 'some_string' } as const;
type values = typeof myObj[keyof typeof myObj];
xxxxxxxxxx
let indexedArray: {[key: string]: number}
let indexedArray: {[key: string]: number} = {
foo: 123,
bar: 456
}
indexedArray['foo'] = 12;
indexedArray.foo= 45;
xxxxxxxxxx
interface MyObjectType {
property1: number;
property2: string;
// Add more properties as needed
}
// Usage example
const myObject: MyObjectType = {
property1: 10,
property2: "Hello world",
// Assign values to other properties
};
xxxxxxxxxx
const satisfies = <T,>() => <U extends T>(u: U) => u;
const mapper1 = satisfies<Record<string, Type1>>()({ foo1: bar1, foo2: bar2 });
const mapper2 = satisfies<Record<string, Type2>>()({ foo3: bar3, foo4: bar4 });
export type MapperKeys = keyof typeof mapper1 | keyof typeof mapper2;
// type MapperKeys = "foo1" | "foo2" | "foo3" | "foo4"
xxxxxxxxxx
Typescript interfaces aren''t being compiled into the js output, and you can not use them at runtime