Skip to main content

Questions tagged [types]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
47 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.4k
-1 votes
0 answers
55 views

Why doesn't a type switch case with multiple types assign the detected type to the variable? [closed]

In Go, I want to understand some design choices in the type switch. The following example works as expected: package main import "fmt" func abs[T int | float64](a T) T { if a >= 0 { ...
Kpym's user avatar
  • 3,909
3 votes
1 answer
53 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.4k
-1 votes
1 answer
49 views

Go type assertion (any) [duplicate]

This seems likely to be a duplicate but I couldn't find a solution. Please point me in the right direction if it is a duplicate I am relatively new to Go and here I am trying to create a helper ...
Emil's user avatar
  • 378
1 vote
0 answers
13 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
19 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,338
1 vote
0 answers
26 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,641
1 vote
1 answer
32 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
  • 43
0 votes
1 answer
127 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
-3 votes
0 answers
89 views

c++ how to convert std::string to std::map? [closed]

i want to know how i can convert a std::string to std::map! map<string, string>New_Map = {{key1, value1}, {key2, value2}, {key3, value3}}; #include <sstream> #include <iostream> #...
Marius Romeiser's user avatar
1 vote
1 answer
59 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
  • 768
-2 votes
2 answers
90 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
-3 votes
2 answers
51 views

Pass Function with Struct Parameter to a Struct in Go [duplicate]

Taking this example struct (my side): type Route struct { // other fields Handler func(any) } This is what the example user of my code would look like: type HelloWorldInput struct { ...
theheavycoder's user avatar
0 votes
0 answers
26 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
29 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
42 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
25 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
52 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
35 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,262
1 vote
1 answer
35 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
34 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
33 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
26 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
48 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,641
0 votes
3 answers
79 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
70 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
62 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
75 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
37 views

Handling Dynamic Outputs in Swift Functions Without Sacrificing Type Safety [closed]

I have a basic custom structure in Swift where I'm aware that using Any for input types is not ideal due to the language's statically typed nature. This approach bypasses the compiler's type checking ...
Adrian's user avatar
  • 35
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
0 votes
2 answers
32 views

Generic types dependencies between function arguments

I'm trying to use binding for a game engine. And I want to add a little typing /** Engine external functions */ export type Message<TBody> = { } // This function returns same unique object for ...
Onni's user avatar
  • 11
0 votes
1 answer
72 views

Should I prefer `dynamic` or `Object?` for generics in Dart?

I've been trying to understand how I should enforce the strict-raw-types rule from Dart, and make sure my code adheres strictly to the type system. I understand the difference between dynamic and ...
Luan Nico's user avatar
  • 5,642
2 votes
1 answer
72 views

Use of protocol as a type must be written with any (Learning Purposes)

I've translated code from a functional programming language to Swift, and it works well when verifying via variables. However, I encounter an error when testing, attributed to Streamable and any ...
Adrian's user avatar
  • 35
-1 votes
0 answers
15 views

Tensorflow is not casting my tensor as type float64 when I want it to, how do I fix it?

It's basically in the title. I'm trying to cast a tensor as a float64 for extra precision and so it can match what the data type of my bias is. However, despite calling the tf.cast function, it's ...
Ric1304's user avatar
1 vote
0 answers
76 views

Why does type inference fail in this Java program?

Let's consider the following Java program: import java.util.*; import java.util.stream.Collectors; public class Main { record Foo(String id, List<Bar> bars) {} record Bar(String id) {}...
Robin Dos Anjos's user avatar
0 votes
0 answers
77 views

"Unable to Create App State Field 'saveforlater' with Document Reference Data Type in Flutter Flow"

Story In my Flutter Flow project, I'm working on implementing an app with functionality similar to a shopping cart. I have successfully implemented the "Add to Cart" feature, but I am ...
KUNAL KUMAR's user avatar
2 votes
1 answer
37 views

Wrapped functions of a Python module raise TypeError

I am currently trying to replace a module in a large code base in a certain condition and to figure out when any function of this module is called, I wrap each function/method in the module with a ...
Green绿色's user avatar
  • 2,335
0 votes
0 answers
20 views

How to Mock a Boolean Hook and a Database Update Call Within a Custom Hook to Bypass Them

The issue I am facing is that I have a custom hook that is asynchronous and does three main things: A. It makes a check; if the check is true, it continues. B. It makes a Firebase call; if successful, ...
Richardson's user avatar
  • 2,171
1 vote
1 answer
80 views

How does the arrow operator in haskell make sense in functions that take more than one parameter?

FYI: Second day into Haskell MRE (what the function does, does not matter): foo :: Int -> Int -> Int foo x y | x == y = x + y | x < y = x | x > y = y This is what ...
kesarling's user avatar
  • 2,102
0 votes
1 answer
26 views

Is there a smart Typescript way to handle complex union type problems with the Notion SDK?

I'm writing a function in Typescript for cloning a specified block/page in Notion using their API. Since there isn't a provided endpoint for duplicating pages programmatically, I've decided to attempt ...
Recaptchow's user avatar
0 votes
2 answers
54 views

How to fix column with numeric values that is taken as a string field because of empty strings in Pandas dataframe?

I have a df with some columns that are supposed to be numeric fields. However, there are empty strings existing in these columns, which leads to their data being incorrectly assigned as 'object'. How ...
szheng's user avatar
  • 5
0 votes
0 answers
23 views

How does the type of attributes of UserRepresentation in Keycloak look like?

In the Keycloak documentation, it just shows that the type of attributes is Map of [array]. There is no illustration. For a Java Map<K, V>, how does the Map of [array] look like, i.e. what're ...
190303458's user avatar
0 votes
2 answers
67 views

Static variable and type: could there be another simpler way to implement a function that returns the same ID for each user-defined type?

I was working on creating an entity-component system on my own, and in doing this I have gotten help from a lot of YouTube videos, C++ references, recommended books, etc. While I was implementing a ...
Luffy_one's user avatar
0 votes
1 answer
48 views

How to create a custom type to parse [u8;32] from a json that contains a hex string in Rust

Given the next json: [ { "dataValueArray": ["0xa4bfa0908dc7b06d98da4309f859023d6947561bc19bc00d77f763dea1a0b9f5"], "dataValue": "...
ARR's user avatar
  • 35
0 votes
2 answers
92 views

Constrain return type to be subtype of this

I have the following interface: internal interface ITyped<EnumType> where EnumType : struct, Enum { public EnumType Type { get; } // !!! this method must always return a subtype* of the ...
Kjara's user avatar
  • 2,742

1
2 3 4 5
581