Showing posts with label TypeScript. Show all posts
Showing posts with label TypeScript. Show all posts

Tuesday, 31 October 2023

TypeScript types , unknow key in object, string with fixed values

 https://stackoverflow.com/questions/26855423/how-to-require-a-specific-string-in-typescript-interface

This was released in version 1.8 as "string literal types"


string with fixed values:

What's New in Typescript - String Literal Types

Example from the page:

interface AnimationOptions {
  deltaX: number;
  deltaY: number;
  easing: "ease-in" | "ease-out" | "ease-in-out";
}


unknown key in object:
https://stackoverflow.com/questions/47847561/typescript-type-for-object-with-unknown-keys-but-only-numeric-values

{ [key: string]: number }? Read the docs on indexable types: www.typescriptlang.org/docs/handbook/interfaces.html