Typescript: Type ‘string’ is not assignable to type ‘”numeric” | “2-digit”‘ in Date::toLocaleDateString()

When you initialize a class property with a literal such as public foo = { bar: ‘a’ }, its type becomes { bar: string }, even if you declare it as readonly. TypeScript on purpose doesn’t make the type too strict ({ bar: ‘a’ }). Method toLocaleDateString accepts an object whose key year must be …

Read more