Questions tagged [types]
Types, and type systems, are used to enforce levels of abstraction in programs.
28,535
questions
-2
votes
0
answers
51
views
Return type by conditional value in C++ [duplicate]
I'm trying to build a simple database engine in C++. I wrote the part of the program that can save things to a file. It's saves the type of the value and the value itself. If the program loads up the ...
0
votes
0
answers
33
views
What is the correct mypy annotation for a tuple where one member's type is conditioned on another member's value?
Update (2023-08-28 2:48 PM): Responding to Jason Harper's logical-but-sadly-not-working suggestion about using literals with more details and a better example.
I'm trying to create a rust-esque ...
1
vote
1
answer
41
views
Type array with optional Ts, required Ks
I want to type an array as needing at least one or more strings at any index, with any extra elements being numbers,
type NumberArrayWithAtleastOneString = [...(number[] | string)[], string]
const a: ...
-1
votes
0
answers
22
views
Get python type from debug and use as a test -> how to [duplicate]
I found a way to do what I want but I am wondering if there is a "better", more pythonic, or industry accepted method for testing for type.
In debug I was testing the type of a variable to ...
0
votes
1
answer
18
views
render component base on the type of a non primitive variable
I've got a issue since a long time that I can't find how to resolve. I would like to check the type of a variable, if it's one type do something else do something else.
In this exemple I use typeof ...
0
votes
1
answer
34
views
Function Types Example Code / Need Explanation / Swift
I'm currently learning Swift function types and the book gives me such code to demonstrate how we can use variables with functions:
var manipulateInteger: (Int, Int) -> Int
func multNumber(_ first:...
0
votes
1
answer
61
views
What am I missing? Java Optional<Long> get returns Object
I have a getter in Java which returns an Optional but when I try to call .get() on it and assign it to a Long as below my compiler and IDE throws an error calling it a type mismatch, claiming it is ...
-1
votes
1
answer
48
views
Golang how to type json HTTP Response Body
I have a nested JSON object being sent in a request body, http protocol. One of the keys of the JSON field starts with an underscore '_'. How can I export the field? Example:
type TopologyGateway ...
0
votes
3
answers
38
views
How to infer and save a type from an array of objects?
There is this very messy API I want to consume, where the values returned are somewhat inconsistent. I could go over every single entry and try and make a type that would cover it, but this would take ...
1
vote
2
answers
50
views
What is the basic type that underlies all other Swift types?
I'm currently trying to get a better understanding of Apple's open-source Swift compiler on GitHub. After using Swift for several years, I've gotten used to the philosophy of defining important types ...
0
votes
1
answer
31
views
Check type of a non primitive variable [closed]
I've got a issue since a long time that I can't find how to resolve. I would like to check the type of a variable, if it's one type do something else do something else.
In this exemple I use typeof ...
0
votes
0
answers
13
views
Use Type annotation in AWS using Python [duplicate]
I want to start to use typed Python.
Is there any documentation with all types for AWS?
For instance, where can I find type for sns_client = boto3.client('sns')?
or lambda_handler event and stufs like ...
-3
votes
0
answers
33
views
File Management System Vs Database Management System [closed]
I am beginning to learn about Database Management System. I am trying to understand, why does the introduction includes the limitations of File Management System ?
Was data stored in a software of ...
1
vote
1
answer
26
views
TypeScript Mapped Types - Is there a way to use interface value type as parameter of function type in mapped type?
I'm not sure how I might precisely describe my goal in words. Here is some code to explain what I would like to do:
type validTypes = string | number
type item = Record<string, validTypes>
...
3
votes
1
answer
112
views
How Can One Express the Fact that `()` is a Subset of All Other (Non-`Void`) Types in Haskell?
I recently started learning Haskell, and I wrote the following code as part of a small parsing library:
-- Successful iff the input string has a length of zero
parseEOF :: Parser ()
parseEOF = Parser ...
0
votes
1
answer
72
views
Unhandled Exception: type '_Map<String, dynamic>' is not a subtype of type 'String?'
I have the following flutter code in my registration_controller.dart
saveBankDetailsUser(
{required String accountName,
required String accountNumber,
required String bankName,
...
0
votes
1
answer
62
views
Fail if type is not provided to builder, unless type is ()
I'm creating an interface which builds a runner over a generic trait implementer:
use std::sync::mpsc::Sender;
trait Poll {
type Output;
type Config: 'static;
fn poll(cfg: Self::Config, ...
2
votes
0
answers
73
views
Typescript: How to satisfy union type with function and arguments
The union of (arg: string) => void and (arg: number) => void is (arg: never) => void, because no value can be a string and a number at the same time. But how can I work around this issue in ...
0
votes
0
answers
51
views
How to detect a program for all Linux (BASH, ASH and SH) without extensions such as "[" or "type"? [closed]
Tried "type" (was told from search results to run "type",)
but "type" had problems, and was told that "type" won't run on all Linux.
Tried:
HasJava=$(type javac ...
0
votes
0
answers
8
views
HasJava=$(type javac || (type ecj && type dx))\nif $HasJava; then /*stuff*/ runs stuff with or without Java [closed]
From How can I check if a program exists from a Bash script? : Do not use "which"; just "type" runs on all Linux
From How to find whether or not a variable is empty in Bash : must ...
1
vote
1
answer
34
views
Explicitly infer object as readonly
I have a function which takes in an object
declare function f<T extends object>(body: T): any;
f({
type: "object",
})
Function signature looks like this:
function f<{
type: ...
-5
votes
1
answer
46
views
How to catch an error from instantiating a Type in Golang? [closed]
EDIT: although the example I gave was happening in main and hard coded, this was intended as a very simple example.
In the real world, bad data might come in at any time and from a multitude of ...
-1
votes
0
answers
51
views
How to find the type of "double" [duplicate]
My homework required me to find the type of double through using ":type" but I failed, can anyone tell me how to achieve it? Thank you!
the entire codes showed:
double x = x + x
double 21
...
0
votes
0
answers
9
views
How to get type metada from typescript compiler api
I need to get information about the types in lib.dom.d.ts so I can check what methods and properties are available in all the different HTML types programmatically.
I mean types like HTMLInputElement ...
-2
votes
0
answers
24
views
"HasJava=`type javac || (type ecj && type dx)`\n$HasJava && echo 1" and "HasJava=`type NotExistAsdf`\n$HasJava && echo 1" both echo "1" [duplicate]
Can add ">/dev/null 2>&1" but got an error.
How to echo 1 for terminals that got Java, and not echo for terminals that do not got Java?
~/java $ type javac
javac is hashed (/data/...
0
votes
1
answer
25
views
ExpressJS, Stripe, Typescript, BodyParser I can not identify the type
So im doing a post on my express server. I'm using typescript
I send an undefined value from my URL in the body (Angular) to the Backend (Express Server).
Before the Object leaves the Frontend via ...
0
votes
1
answer
24
views
CHanging the data type from text to date in a column
i have a table named players_wc where there is a column name Player_DOB whose data type is text.
the values inside the column are like 02-09-1992. i need to change the data type of the column in order ...
0
votes
0
answers
40
views
Why is my mypy.ini file not followed for no implicit optional checks during type checks?
I have a mypy.ini file and I can confirm that it's getting picked up when I run mypy --strict . However, for some reason (even though I have the strictest settings enabled in my mypy.ini file) when it ...
3
votes
1
answer
54
views
Are comparisons really allowed to return numbers instead of booleans, and why?
I've found a surprising sentence in the Python documentation under Truth Value Testing:
Operations and built-in functions that have a Boolean result always return 0 or False for false and 1 or True ...
0
votes
0
answers
6
views
Python TypeError: < not supported between instances of str and int in training model
I'm encountering an issue when trying to convert an object to a string in Python. Specifically, I'm working with a dataset for a Named Entity Recognition (NER) task (new at this), and I need to ...
0
votes
2
answers
29
views
Why can I use `as` but not assign the type for mapped values in typescript?
I have a list of objects, which are declared with as const.
I also need a list of the same values from the objects, but don't want to maintain two lists.
And so i have this...
export const ...
0
votes
0
answers
28
views
In what case the contravariance of function arguments is useful?
We know that for two function types T1→T2 and S1→S2, T1→T2 ≤ S1→S2 iff S1≤T1 and T2≤S2 (ref). But I cannot come up with a realistic case where we want S1≤T1, as more likely we will use template/...
0
votes
3
answers
50
views
KDB/q How to use qsql select statement to find item in list where type is empty list in a column of characters?
I have a table and passed it into a function where I use the primary ID to generate a column of characters.
However, there are a few areas in this newly-created column where instead of characters it's ...
1
vote
2
answers
24
views
Is it possible to use the elements of Array<keyof T> as indeces of T?
Hi I want to create a function that takes two parameters an array of objects "T[]" and a array of fields of the T. However I keep getting the following problem in the line where I call el[...
0
votes
0
answers
20
views
How do I enforce a maximum depth and value requirements for a multi-dimensional object containing objects and arrays of primitive (only) values?
Introduction:
I have a multi-dimension object in a TypeScript file, that would look something like this:
const store = {
key_1: "value",
key_2: 123,
key_3: true,
key_4: {
key_4_1:...
1
vote
0
answers
32
views
Go YAML unmarshal to custom type - how to convert?
I am trying to unmarshal a YAML to a structure with multiple fields, some of them with custom types. One of those types is simply
type customType string
However, if I try to assign a string value, to ...
3
votes
1
answer
45
views
Understanding into() to resolve constant generic expression type mismatch in nightly Rust
I'd like to understand the following compiler error while using feature(generic_const_expr) in nightly Rust. As I am still learning Rust, it could very well be due to lack of my understanding of the ...
0
votes
1
answer
61
views
C++ template method specialization by type traits
I'm working in C++11, creating a class template. I wish to optimize certain methods according to the type traits of the template parameter (i.e. float/integer, signed/unsigned etc.). I know this could ...
1
vote
1
answer
24
views
No index signature with a parameter of type 'string' was found on type '{}' - TypeScript
I read key value pairs from a file, the key is string and the value is {r,g,b} numbers.
colorNames.json file:
{
"name1": { "r": 151, "g": 23, "b": 26 },
&...
1
vote
2
answers
100
views
NumericUpDowns included in iteration over TextBoxBase controls
I have a WinForm with NumericUpDowns (NUDs), normal TextBoxes and MaskedTextBoxes.
The text boxes should be cleared, which I tried this code for:
For Each txtBox As TextBoxBase In Controls.OfType(Of ...
0
votes
0
answers
36
views
Data type error while reading Parquet files in pyspark
I have converted a bunch of CSV files into parquet files, and while trying to load 5 rows of the parquet files into another Pyspark dataframe, I got an error.
How I converted my CSV files into Parquet ...
1
vote
1
answer
33
views
Is it possible to overload Generic parameters in TypeScript?
I'm coming from C# and there you have functions parameters defined as a class.
Action // void method
Action<T1> // void method with a T1 parameter
Action<T1,T2> // void method ...
-1
votes
0
answers
27
views
How to name TS types in between controller - service and database access layer
This question will probably getting downvotes and become closed due to too opinion based but I don't know where else to ask since I can't find blogs/courses going beyond there 'happy'-examples.
I'm ...
0
votes
0
answers
24
views
mypy not found after pip installation
I have installed mypy as instructed on the Getting Started page (python3 -m pip install mypy).
When I try running mypy program.py as recommended, I get zsh: command not found: mypy.
pip3 mypy shows: ...
-3
votes
0
answers
44
views
TypeError: a bytes-like object is required, not 'int' help pls
Help me pls, i dont know why this code dont work
Can anyone help me with the code, otherwise it really doesn’t work, I’ve already done everything, tried to connect libraries, it doesn’t work either, ...
3
votes
2
answers
40
views
A question about the argument types to the comp predicate in std::lower_bound
Reference: std::lower_bound
Excerpt:
comp - binary predicate which returns true if the first argument is less than (i.e. is ordered before) the second.
The signature of the predicate function ...
0
votes
1
answer
37
views
SQL UNION on different column lengths and data types
I have two tables
CREATE TABLE LOGIN
(
[ID] INT NOT NULL IDENTITY(1,),
PASSWORD VARCHAR(30) NOT NULL,
CONSTRAINT [PK] PRIMARY KEY ([ID] ASC)
)
CREATE TABLE HASH
(
PSWDHASH VAR(100) ...
0
votes
1
answer
24
views
Why does typescript dons't do typecheck on a 2d array?
I have this simple code to generate a 2d array:
type cell = {
id: string;
};
const board: cell[][];
board = Array(10)
.fill("")
.map((x) => Array(10).fill(ANY TYPE CAN GO ...
0
votes
1
answer
39
views
How can I write this function signature in typescript?
I have a minimal reproduction of a recursive type problem I've encountered. Here's some typescript.
type Cloneable = string | number | Cloneable[];
function clone<T extends Cloneable>(arg: T): ...
0
votes
0
answers
38
views
Passing Type to generic method [duplicate]
I want to pass a Type to a generic method in C#.
Here's a simplified example of what I am trying to do:
public void myMainMethod()
{
Type t = typeof(myClass);
myGenericMethod&...