Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [types]

Types, and type systems, are used to enforce levels of abstraction in programs.

types
0 votes
1 answer
20 views

Rust generic lifetime elision issue

I am trying to a implement generic observable collections for use with a UI framework I'm writing. I'm currently having an issue with lifetimes not being elidable in generics. For brevity the ...
Jacob Green's user avatar
0 votes
0 answers
23 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} ...
josno's user avatar
  • 96
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. ...
TNTzx's user avatar
  • 527
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 ...
wolvesback019's user avatar
0 votes
1 answer
61 views

Get templated struct without knowing initial template arguments

I am looking for a way to get a specified templated struct from the custom Node classes I am building without having to static_cast or dynamic_cast when I get the pointers. What ways can I use to ...
JemmaFromJupiter's user avatar
0 votes
1 answer
16 views

Pydantic union discriminator not being used for FastAPI response

I have the following Pydantic models: class Activity(BaseModel): activity_key: ActivityKey activity_id: UUID = Field(default_factory=uuid4) questions: list[QuestionWithDistractors] | list[...
KOB's user avatar
  • 4,395
2 votes
2 answers
52 views

How to convert data frame in R to a "character" data type?

The labeller function which I'm using for ggplot requires data of the type: tempdat <- c( "1" = "one", "2" = "two" ) If I use typeof(tempdat) it gives ...
blackthorne18's user avatar
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 '...
avenmia's user avatar
  • 2,565
0 votes
0 answers
19 views

Problem with the error message displayed in a form

I would like the user to take into account in the form that the numbers are entered with periods and not with commas and I have a problem: the error message is displayed when entering a decimal number ...
Valery's user avatar
  • 1
0 votes
0 answers
34 views

Cannot map the input column, 'Date', to the lookup column, 'Date', because the data types do not match

I'm getting this error: TITLE: Microsoft Visual Studio Cannot map the input column, 'Date', to the lookup column, 'Date', because the data types do not match. Data type in SSMS Changed type to date, ...
emmaS's user avatar
  • 1
-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 ...
meclondrej's user avatar
-1 votes
2 answers
88 views

uint8_t elements exceeding one byte?

I saw this code: uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; I know uint8_t holds a byte, so how does this line of code work when a single element, 0xFF, is in itself one whole ...
bittybytey's user avatar
0 votes
0 answers
22 views

R visNetwork arrow type

The below code is meant to yield the following network graph: . library(visNetwork) library(magrittr) nodes <- data.frame(id=c("a","b","c","d"), label=c(&...
jbowerbir's user avatar
1 vote
3 answers
101 views

In C, why can a variable holding a char array be assigned to a pointer, but the address of the same pointer cannot?

Consider the following code: char stringy[] = "There's too much confusion, I can't get no relief!"; char *pStringy; pStringy = stringy; This compiles - stringy is an array of characters, ...
Bennypr0fane's user avatar
0 votes
1 answer
134 views

Write a new Delphi type that lets a method have inline code as a parameter?

Is it possible to have this in Delphi? DoThis(ShowMessage('SomeMsg ..'); Caption := 'SomeCaption'; Inc(I)); Is it possible to create a new type that handles inline code like this? For example, we ...
MBen's user avatar
  • 19
1 vote
1 answer
39 views

R get local variable from formula

Consider the R code : foo <- function(formula){ Y <- get(formula[[2]]) print(Y) } main <- function(){ Y <- 1 X <- 2 foo(Y ~ X) } main() The outcome says that in get(...
温泽海's user avatar
  • 344
0 votes
0 answers
22 views

check if given object implements certain generic interface; type argument(s) NOT known [duplicate]

I have some object. I want to check at runtime if it is an IReadOnlyCollection<T> of any T, i.e. I cannot specify that T in my check. So it should return true for e.g. IReadOnlyCollection<...
Kjara's user avatar
  • 2,794
0 votes
0 answers
37 views

As a wrapper object in JavaScript, why can not use 'new' to create a BigInt in JavasScript? [duplicate]

There are 5 wrapper objects in JavaScript: Number, BigInt, String, Boolean, and Symbol.You can use 'new' to create a Number, String, Boolean, Symbol. But you can not use 'new' to create a BigInt. what ...
Leo qiao's user avatar
-2 votes
0 answers
80 views

Are there objects for primitive data types? [duplicate]

If the object represents a data type, is the variable for a primitive data type like an integer also an object representing this type, or do objects not represent primitive data types? // Let's assume ...
Ahmed Hamed's user avatar
1 vote
1 answer
55 views

Why print(f"{variable = }") in Python 3.12 also prints numpy type?

I noticed, that with Python 3.12 and a numpy.float64 when I simply do a x = numpy.sqrt(3) # type is <class 'numpy.float64'> now print(f"{x = }") # this is printed >>>x = np....
emefff's user avatar
  • 11
0 votes
1 answer
53 views

How to enforce error on impossible switch case?

There is a linter we can enable for equality check. What about switch case ? This does not seem to work. https://stackoverflow.com/a/78736339/6727914 How to convert the warning into errors ? Example: ...
TSR's user avatar
  • 19.5k
3 votes
1 answer
62 views

How to enforce error on impossible equality check?

There is a linter to it https://dart.dev/tools/linter-rules/unrelated_type_equality_checks but it just shows a warning, rendering it almost useless for large projects. How to convert the warning into ...
TSR's user avatar
  • 19.5k
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. ...
The Elina's user avatar
0 votes
1 answer
21 views

Checking subclass against metaclass type

I have a set of plugins that inherit from a metaclass. the metaclasss is defined like so: from abc import ABC, abstractmethod class MetaReader(ABC): def __init__(self, arg1, arg2, **kwargs): ...
KBriggs's user avatar
  • 1,362
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 ...
Jarek's user avatar
  • 7,673
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 ...
yzkael's user avatar
  • 67
0 votes
1 answer
161 views

How to parameter pack pairs of types?

Here's an example usage of a parameter pack: template <typename... T> bool foo(A x) { return (baz<T>(x) || ...); } I'd like to do something similar, but with pairs of types. Here's an ...
user129393192's user avatar
2 votes
1 answer
62 views

C# generic method detect if T is array and then index into the array

I'm trying to write a Dbg debug function that will print out some debug info about the given parameter and then return it. I would like arrays to be printed as the list of elements, and scalars to ...
beyarkay's user avatar
  • 809
-2 votes
2 answers
94 views

Custom integer-like datatype with support for static casts without warnings

I'm writing my own little utility library, and I've opted to do something which I don't really see often (and there might be a reason) - I'm trying to implement a 'perfect' wrapper around C++ integer ...
Goubermouche's user avatar
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; }...
Jaco's user avatar
  • 11
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&...
João Pedro's user avatar
-2 votes
0 answers
38 views

Returning an array of raw type but instead of an array of parameterized type specified at the header

protected Collection<Node> createBucket() { return new LinkedList<>(); } /** * Returns a table to back our hash table. As per the comment * above, this table can be an array of ...
Pius's user avatar
  • 1
0 votes
0 answers
39 views

Joda-time type mapping in Hibernate ORM 6

I'm new to Java and I am trying to migrate from Hibernate 5 to 6. My application uses joda-time for the timestamp data type. It is using both annotation and hibernate mapping files. Following is a ...
tieuquynd's user avatar
0 votes
1 answer
49 views

Dynamically set the Property name to be the name of the Type(typeof(T).Name)

var appsettings = JsonConvert.DeserializeObject<AppSettings<PersonModel>>(configData); class AppSettings<T> { [JsonProperty(PropertyName = typeof(T).Name)] public T ...
Imran K's user avatar
  • 15
2 votes
1 answer
44 views

Casting RDD to a different type (from float64 to double)

I have a code like below, which uses pyspark. test_truth_value = RDD. test_predictor_rdd = RDD. valuesAndPred = test_truth_value.zip(lasso_model.predict(test_predictor_rdd)).map(lambda x: ((x[0]), (x[...
Inkyu Kim's user avatar
  • 145
1 vote
0 answers
30 views

When using WC_Product_Variable, it creates a simple product [duplicate]

I am trying to progmatticly create a Variable Product in WooCommerce like so: $currentProduct = new WC_Product_Variable(); $currentProduct->set_name( $product['Title'] ); ...
francis astin's user avatar
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 ...
Mauricio Esparza's user avatar
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 ...
goose_lake's user avatar
  • 1,272
1 vote
1 answer
37 views

PowerShell - cast a variable type based on a variable definition

I've got a hashtable with variables. The source of this hashtable is an empty parameters.json (for deployment of Azure resources) converted to a hashtable. For this question I have simplified this ...
TheBrickAdmin's user avatar
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, ...
Britton Kerin's user avatar
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 ...
Jonas's user avatar
  • 13
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: ...
Tomas's user avatar
  • 3,388
0 votes
1 answer
50 views

TypeScript types - accessing function's argumets Tuple type from function call (Fn type generated by another type)

Edit: I completely changed question after playing with this a little today: Playground I start from the end, with example that for sake of simplicity wants to get a correct first argument user ...
Jarek's user avatar
  • 7,673
0 votes
3 answers
82 views

Can a Go interface receive any function, regardless of its signature?

EDIT: A couple of the answers have suggested changing the signature of the RegisterHandler function, however as part of the original question I asked if it were possible to further restict the types, ...
Masa Maeda's user avatar
0 votes
0 answers
25 views

Why "No errors!" from Hegel when there's a JS file with errors in it?

I'm following the steps on Hegel's website but it's saying "No errors!" even when there's a JS file in the same directory with an error in it that's picked up by the online Hegel playground.
Will White's user avatar
1 vote
2 answers
73 views

Can't understand the reason for this Typescript generic issue

I am learning TS and have the following code: function getOrDefault<T = string>(value: T, defaultValue: T, car: T): T { return value || defaultValue; } const strValue = getOrDefault("...
j obe's user avatar
  • 1,969
1 vote
1 answer
87 views

Inherited functions returning self reference with derived type

I am trying to create a system where one base class has a bunch of functions, then derived classes can inherit it and add more functions. However, all of these functions return the this keyword and I ...
CreeperCrafter979's user avatar
1 vote
1 answer
66 views

Handling Dynamic Outputs in Swift Functions Without Sacrificing Type Safety (Any)

I have a basic custom structure in Swift where using Any for input types is less than ideal due to the language's statically typed nature, which can bypass the compiler's type checking and lead to ...
Adrian's user avatar
  • 35
0 votes
0 answers
76 views

c++ warning: non-void function does not return a value in all control paths

warning: non-void function does not return a value in all control paths... I know what it means, because the for loops don't return something when the data is empty. How should I fix it? template<...
Marius Romeiser's user avatar
0 votes
0 answers
28 views

What is the benefit of Axios' type variable for response data?

Axios request functions are typed as get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R> (delete, post, etc. are analogously typed), where ...
Jonas's user avatar
  • 13

15 30 50 per page
1
2 3 4 5
579