All Questions
Tagged with types typescript
4,239
questions
0
votes
0
answers
22
views
Creating a type from an object's keys and values in TypeScript
I'm trying to create a new type based on the type of a statically defined object in TypeScript. Given the following map:
const map = {
'hello': {a: 1, b: false},
'world': {b: 'hello', c: null}
...
3
votes
1
answer
30
views
Typescript: Variable inside Express RequestHandler becomes possibly undefined despite being checked in an if statement [duplicate]
I am creating a way to dynamically create routes before the server fully starts (meaning I'm not creating a route via a request lol that would be crazy), and I stumbled upon this interesting quirk.
...
1
vote
1
answer
21
views
Why does Typescript loses inference on nested objects when accessing them with dynamic property names?
Playground: https://tsplay.dev/m3Gqqm
I'm trying to access deeply nested properties of my theme object based on input parameters, so I can provide a nice dev experience by having autocomplete.
But ...
0
votes
1
answer
19
views
How to fix: Property 'geocodeService' does not exist on type 'typeof import("node_modules/@types/esri-leaflet-geocoder/index")'
I'm having a typing issue with the Esri Leaflet Geocoder types package. https://www.npmjs.com/package/@types/esri-leaflet-geocoder
Here is how I'm importing it:
import * as L from 'leaflet';
import '...
-1
votes
1
answer
53
views
Picked structs in rust
Is it possible to have a picked struct in such a way that the type checker doesn't have a problem with it?
Coming from TypeScript:
// Considering a main object type containing all fields:
interface ...
1
vote
0
answers
18
views
Why am I having an issue with typescript and Prisma ORM when trying to find a unique item?
I am having issues with my ability to use the prisma .findUnique() function call. My code doesn't show any compilation error, but when I actually try to go to a product page it causes a runtime error.
...
1
vote
0
answers
28
views
Unexpected behavior when combining mapped type created from Union that is used within conditional type [duplicate]
I came across some unexpected behavior when trying to expand mapped type I created from an union of object types, when trying to use this type within conditional type: Playground
export type ...
1
vote
1
answer
46
views
How to Properly Implement Role-Based Authorization in React Using Context API and React Query?
I am trying to work on a React application where I want to implement role-based authorization.
My goal is to fetch user roles from an API and store them in context so they can be accessed throughout ...
0
votes
0
answers
32
views
exported variables always return undefined in discord.JS V14
in events/messageCache.ts:
import { Events, Message } from 'discord.js';
export interface MessageCacheEntery {
authorID: string;
deleted: boolean;
message: string;
timestamp: number;
}...
1
vote
1
answer
32
views
Extract Generic Interface or Type keys as an Array [duplicate]
I want to know if it's possible to get a generic interface or type and get it's properties like an array of objects, like this:
interface UserData {
email: string
}
keys = extractKeys<UserData&...
0
votes
2
answers
62
views
TypeScript Type narrowing not working for collection schema
I'm working on an Astro + TypeScript project where I have few data collections with specific schemas.
I'm using the Zod library to define and structure each data collection, which in a simplified way ...
0
votes
1
answer
39
views
Is it possible to annotate the type of a Svelte component?
I have several Svelte components, for example: Melon.svelte, Cherry.svelte, Phone.svelte. In a parent component, FruitBox.svelte, using <svelte:component>, I want to be able to dynamically ...
1
vote
1
answer
37
views
why can't typescript figure out that the possible actual types of a union type correspond to the available prototypes for a function? Workaround?
This (playground link) doesn't work:
type ReplaceAll2ndArgType = string | ((substring: string, ...args: unknown[]) => string)
export async function renderHTMLTemplate(
args: Record<string, ...
0
votes
1
answer
35
views
Why is the type {} inferred instead of unknown when strictNullChecks is disabled?
Consider the following code:
const { name } = "something" as unknown;
When I enable Typescript's strictNullChecks, I get the following error message:
Error: Property `name` does not exist ...
0
votes
1
answer
27
views
Getting object name limited to values defined in Set in TypeScript
I have some Set, which defines some IDs:
export const IDS: Set<number> = new Set<number>([1, 30, 50, 9999]);
Now I'd like to define mapping for their ID-SHA pairs in object structure:
...