Questions tagged [types]
Types, and type systems, are used to enforce levels of abstraction in programs.
26,004
questions
1
vote
1
answer
19
views
infer values from objects using object keys
Been looking for an answer for this, but couldn't find an exact one.
I have to following code example:
interface RowData {
firstName: string;
lastName: string;
age: number;
participate:...
0
votes
0
answers
13
views
Type 'Recommendation[]' does not satisfy the constraint 'PathParams'. Index signature for type 'string' is missing in type 'Recommendation[]'.ts(2344)
I am building a app using react, typescript and msw. When I am adding types I got this error:
Type 'Recommendation[]' does not satisfy the constraint 'PathParams'. Index signature for type 'string' is ...
0
votes
0
answers
13
views
TypeScript types to restrict array values
Can I use TypeScript types to restrict array inputs to certain elements?
For example, if I wanted to create a type that is an array that could hold any number of elements, but the elements are ...
0
votes
0
answers
27
views
How to declare a type whose key and value of an object are associated with enum in TS?
How to declare the type of an object in typescript, its key is an enumeration member of enum, its value is a function, and the parameters of this function are related to the key?
Details are as ...
2
votes
1
answer
37
views
How to type multiple similar python functions with the same overload signature
I have two functions that are quite similar, the second one calles the first one (and in the actual code does something else afterwards).
Both take two arguments that can take multiple types, bot only ...
0
votes
1
answer
31
views
How to properly find out type in javascript?
In this code sample:
level.js:
class Level {
setLevel(level) {
// if (typeof level === "number") {
if (level.constructor === Number) {
this._level = level;
}
}
...
0
votes
0
answers
17
views
Mypy error while creating dynamic class from classmethod
I am creating a dynamic class from an abstract base class. Here is a simplified example.
from abc import ABC
from typing import List, Type
class IParentClass(ABC):
_children: List['IParentClass'] ...
0
votes
1
answer
23
views
What does this mean in angular, what kind of type is this?
I would like to know what this type means:
type newtype = (state: EntityState<IEntities>) => IEntities[];
-1
votes
1
answer
33
views
SQL Server : unable to save decimal digits
I am facing a peculiar problem. I have a few tables in SQL Server where I have properly declared a few columns as decimal(18, 2).
Unfortunately, whenever, I save any value in these columns, either the ...
0
votes
1
answer
24
views
Typescript: Enforcing property type based on another property value which is a key of a generic
Given the following type:
export type MyType = {
a: boolean;
b: number;
}
I want to create a type:
export type Mapper<T> = {
key: keyof T;
func: (value: string) => T[key];
}
...
0
votes
0
answers
36
views
Which C/C++ data type should I use for PHI(N) calculator?
I found a source code online for calculating PHI.
I made some small adjustments to the variable types, such as using an unsigned long int, however I am limited to input numbers that are too small for ...
1
vote
2
answers
64
views
How can you define a function who's return type depends on the value of its parameter?
Let's say I want to define a function called zero that takes a string like "f" or "i" and returns the zero value for either float or int.
So we could do something like this (I have ...
1
vote
0
answers
39
views
How can I add constraints to a type in a data type in haskell? [duplicate]
I have a data type called Time in Haskell that has hour, minute, and seconds.
data Time = Time
{ Hour :: Int,
Minute :: Int,
Second :: Int,
}
deriving (Show, Eq)
When defining a data ...
-4
votes
0
answers
54
views
How do i convert this custom data type to a string in haskell [closed]
type Station = (String, Float, Float, [Float])
testData :: [Station]
testData = [("Mumbles Head", 51.565, -3.981, [8.26, 8.33, 9.84, 12.36, 15.24, 17.83, 19.55, 19.67, 17.97, 14.70, 11.49, 9....
-2
votes
2
answers
57
views
Check Type of Variable in Go [duplicate]
In other languages, I can check the type of a variable at run time like so:
# Python
return foo is str # check that variable foo is of type string, true or false
// C#
return foo.GetType() == typeof(...
0
votes
3
answers
25
views
Oracle PLSQL extend type with date abs timestamp
I have the following code, which seems to be working. Is there a way I can add a date, timestamp to the type definition? If so, how would reference the columns so I can INSERT data into them. For ...
0
votes
0
answers
30
views
How can I change column data type in MySQL when there are blank rows in some columns
I did some data cleaning and the last step is to change the data type of 3 different columns each from varchar to datetime, float and integer. MySQL gives me errors in locations where there are blank ...
0
votes
0
answers
25
views
Can I short-circuit type evaluation?
I'm trying to create a composable configuration framework wherein each node in the dependency graph can access all of its upstream nodes. Although I've managed to express this by explicitly declaring ...
0
votes
2
answers
19
views
How to add a value within specific key when extending an interface?
Let's say I have an interface:
interface Person {
age: number
name: {
first: string
second: string
}
}
And I want to extend Person to Friend, which would look exactly the same as Person ...
2
votes
1
answer
30
views
Is there any reason or advantage to specify string column length in BigQuery?
I am new to BQ and experienced in OLTP RDBMS, I found the data in BQ for my company are mostly in STRING type while it was VARCHAR(255) or even less in the OLTP DB.
Is there any reason or advantage to ...
0
votes
0
answers
16
views
Declare types from file with `export .. from` to global interface
I have the file with a lot of export { default as NAME } from './PATH_TO_FILE';
And I want to declare types to global @vue/runtime-core inside GlobalComponents. But my try isn't working.
import * as ...
0
votes
1
answer
14
views
Correctly declare interface or type for functions params
How to correctly declare type for param cardsByStatus inside function addCardsToStatus? It works for cardsByStatus: any, but it doesn't make sense for me.
Error: Property 'map' does not exist on type '...
-1
votes
0
answers
8
views
MYSQL data type incorrect
I have imported .csv table in MYSQL Workbench, and want to create new table with existing columns from .csv but when I created new table and set data types there is an error for DATE because not all ...
1
vote
1
answer
84
views
Defining new types in Haskell
I am pretty new to Haskell, and I was wondering if one can define new types that are defined by lists of other types. For example, I assume a string is defined as a list of characters, so can I define ...
1
vote
0
answers
9
views
Typescript type or declare and not repeat jsDoc
I am having problems to understand witch one should I use type or declare in this case. Also with declare the jsDoc comments are showed in the IDE, but not the type jsDoc comments, but either declare ...
-1
votes
0
answers
16
views
fix circularly references itself
Hey i get some advanced code i got stuck,
i Will like to get some help
this code
this is not an easy case, thanks for all those how will try to help
0
votes
0
answers
35
views
SQL to Show Custom Tables Microsoft SQL Server
I created a table type in SQL Server so I could pass a data table into a stored procedure using c#. Is there a SQL Statement I can use to see all the custom table types that were created.
CREATE TYPE ...
0
votes
1
answer
18
views
Generate empty object based on reactively interface
I have interface that is generated base on enum and it has readonly keys
enum HealthPlanStatus {
InProgress = 'InProgress',
Completed = 'Completed',
}
export type THealthPlanCardsByStatus = {
...
0
votes
1
answer
76
views
Append to existing tuple in c++
i am trying to make a thing to store types in list. The best thing is to use a tuple. then to get the type i use tuple_element_t. But the problem is when appending to the tuple so i can store more ...
1
vote
0
answers
12
views
Typescript Omit Accepts Wider Types
Typescript allows the following, wondering if is this by design? I was thinking it should not be allowed to return
a "wider" Point inside a function that wants to return Omit<Point, '...
0
votes
1
answer
17
views
Type Error: argument of type 'Word2Vec' is not iterable
doc2vecs = Doc2VecTrainer(Xs, embd_size, w, min_word_count, worker_threads)
File "C:\Users\PC 5\Desktop\embedding.py", line 63, in Doc2VecTrainer
if Samples[i][j] in word2vec_model:
...
0
votes
0
answers
13
views
Alternative to typoetools TypeResolver library
I am working on a project in which we are using typetools library and when we've tried to upgrade to Java 17 it broke because of this library, it seems it's not supported anymore and something's going ...
0
votes
0
answers
44
views
`yarn upgrade` on React Typescript NextJS app "element type 'ReactElement<any, any> | Component<{}, any, any> | null' is not a valid JSX element"
I'm working on a React Typescript NextJS app. Had to upgrade NextJS due to the image cache issue (not related). I've managed to sort that, but... my colleague suggested running yarn upgrade, and now I'...
2
votes
0
answers
37
views
Cannot infer type-variable(s) generics issue in Java [duplicate]
This question may have some similar ones, but I hope you can look at the code structure here and provide some insight. I believe this either demonstrates a very subtle user error, or a very subtle ...
0
votes
1
answer
16
views
Kotlin compile error using self generic type bound
Suppose I have the following code to simulate a state machine in Kotlin:
sealed interface State {
object A : State
object B: State
object C: State
object D: State
}
interface ...
0
votes
0
answers
18
views
Generating TypeScript types from a Map
Is it possible to generate typescript type from a JS Map or equivalent objects?
eg.
type SampleType<T> = {
name: string;
handle: (value: string) => T;
};
I have a list of objects ...
0
votes
0
answers
6
views
How to avoid automatic placement of second quotes in python?
I got two question please...
How to avoid automatic placement of second quotes in python?
example: I am writing something like: print("... and here python put the second " automatically on a ...
1
vote
1
answer
36
views
safe type debounce function in typescript
I have the following debounce function in typescript:
export function debounce<T>(
callback: (...args: any[]) => void,
wait: number,
context?: T,
immediate?: boolean
) {
let timeout:...
0
votes
0
answers
26
views
Serial Read - Arduino
I am a new programmer, so I am having a bit of problem with Serial communication of Arduino.
I am trying to read data from serial Input, sent by a simulation as characters and I need to store it as ...
0
votes
0
answers
35
views
PHP considers array as object [duplicate]
I have a strange case of a member of an object that is displayed as type 'Array' in print_r or var_dump, but that is seen as an object by PHP.
Here is what var_dump displays when I do var_dump( $xml);
...
2
votes
1
answer
13
views
How to omit an union type depending on field value
I have this type (come from third party library):
type StackActionType = {
type: 'REPLACE';
payload: {
name: string;
key?: string | undefined;
params?: object;
};
...
1
vote
0
answers
40
views
Scala variance positions - theory behind it?
Scala has notion of "variance position" and fancy rules around it, especially when variance is combined with method type bounds. Rules ensure type safety, one can read them in Scala lang ...
-1
votes
1
answer
48
views
Primitive type of 32.0 % 6 in Java [duplicate]
I'm taking an intro to Java class that asks the following question:
Select the primitive type of this expression's result: 32.0 % 6
choices: int, float, double, long
I chose float, but the correct ...
1
vote
2
answers
32
views
Replace Parts of Literal String with Values From Object
I'm having trouble figuring out a particular bit of Typescript magic. I would like a StringReplaceAll generic which is used like this:
type Replaced = StringReplaceAll<"greeting adjective ...
1
vote
1
answer
30
views
Typescript event listener - type to props mapping
export enum GameEventType {
EVENT_ONE = 'event-one',
EVENT_TWO = 'event-two',
EVENT_THREE = 'event-three'
}
export type GameEvent =
| { type: GameEventType.EVENT_ONE; parameter: string }
| {...
1
vote
2
answers
25
views
How to set a good condition for dynamic property of object
I have an array of objects:
export const inputsArray: InputAttributes[] = [
{
label: 'Name',
type: 'text',
name: 'name',
required: true
},
{
label: '...
0
votes
1
answer
22
views
How to get storybook to display typescript types in stories
Storybook tells us how to write a basic story using typescript.
// Button.stories.ts|tsx
// ... Your imports go here
export default {
/* 👇 The title prop is optional.
* See https://storybook.js....
5
votes
1
answer
113
views
+250
How to include a global file type declaration in a TypeScript (Node.js) package
I'm working on a package that I am planning to publish publicly on npmjs. Let's call it the "text package".
I would like that by default when installing that package, you can import .txt ...
0
votes
0
answers
19
views
React Upvote & Downvote divs to vote only once
I have a reddit like post where I can Upvote and downvote.
<div className="post-card__vote-container">
<div
onClick={() =>
dispatch(
...
0
votes
1
answer
43
views
React-Dropzone, accepted files MIME type error
I´m currently building a react drop zone for obvious reason, but am getting those weird errors:
Skipped "accepted" because it is not a valid MIME type. Check https://developer.mozilla.org/en-...