Questions tagged [strong-typing]

A typing system that enforces restrictions on which operations or methods may be called on an object based on type.

Filter by
Sorted by
Tagged with
1 vote
2 answers
47 views

How to patch form array in typed angular reactive forms

I am trying to figure out how to patch form array in a typed reactive Angular form. patchValue and setValue does not work in my mind consistently with FormControl for example. Here is a form this....
Sergey Barskiy's user avatar
2 votes
0 answers
115 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 ...
Pietro Carrara's user avatar
0 votes
1 answer
48 views

TypeScript: How to initilize keyof T (generic) at runtime

so I have this TypeScript class where I have a generic and a property of type keyof generic, like this: export class ColumnDefinition<T> { field: keyof T } Compiler complains because it ...
Heila Al-Mogren's user avatar
0 votes
0 answers
17 views

Unable to load Serilog.Enrichers.CorrelationId, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null since it is not strongly typed

I am trying to load Serilog from an assembly which is strongly typed and is in GAC. I am unable to load assembly Serilog.Enrichers.CorrelationId, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null, ...
NV13's user avatar
  • 11
0 votes
1 answer
22 views

How to define static variables in TypeScript [duplicate]

I want to define an array with a constant value e.g. const arr = ["a", "b"];. However, the compiler will think it's string[]. Is there is a way to make it a constant type as is so ...
masinnlos's user avatar
  • 137
3 votes
2 answers
80 views

TypeScript method to wrap any method of another class

I have the following setup in TypeScript: abstract class Test { public abstract method1(param1: string): number; public abstract method2(param1: number, param2: string): Promise<number>; ...
CrystalSpider's user avatar
0 votes
2 answers
66 views

Raising compile-time errors in order to constraint possible permutations of a struct in Rust

Imagine a struct... struct Pair { letter: Letter, number: Number, } enum Letter {A, B, C} enum Number {One, Two, Three} The total number of combinations in this struct would be 3 x 3 = 9, ...
StaticESC's user avatar
1 vote
1 answer
85 views

Type Challenge 11 Tuple to Object

I am fairly new to strong typing but have been working in TypeScript for a little while now. I am starting to work through the Type Challenges to get better at strong typing and having a strong ...
kalisjoshua's user avatar
  • 2,336
1 vote
1 answer
1k views

Get Literal types for object keys in typescript dynamically?

I want to get object keys type, here i write a generic for object with keys as string type GenericInput = { [key:string]: {value:string,type:HTMLInputTypeAttribute,placeholder:string,min?:number,max?...
Badar's user avatar
  • 33
1 vote
1 answer
43 views

Determining the type of a value based on a if check on another value

I want my code editor to infer the type of extraData based on the value of error which is being narrowed by the if statement: export enum ErrorCodes { Unknown = 'UNKWN', BadRequest = 'BDREQ', } ...
Jenryk's user avatar
  • 13
0 votes
1 answer
54 views

Using a subset of an object in different services

lets say that I have a system that heavily relies on a single object, for example a Person. I have a storage service (service 1) that handles basic CRUD operations for Person, and saves this person in ...
arebok2's user avatar
0 votes
2 answers
514 views

io-ts to strict validate if object has no declared property

I'm using io-ts to do input validation for an API. I need to ensure there has no un-declared property in the requirement object. For example, if I define the interface of request as following: const ...
Colin Han's user avatar
3 votes
1 answer
600 views

Conditional types with mypy

I have the following code snippet: from typing import TypedDict class Super(TypedDict): foo: int class SubA(Super): bar: int class SubB(Super): zap: int def print_props(inp: Super, key:...
daflodedeing's user avatar
0 votes
1 answer
375 views

How to get type hint in php array similar to java or typescript?

I read various articles claiming that now php-8 also is strongly type language https://medium.com/codex/php-became-strongly-typed-66f2b2ae917. Since I work with typescript, i was looking for same IDE ...
Badar's user avatar
  • 33
1 vote
1 answer
360 views

How to achieve strongly typed integers in Python

I don't think that I like that the following is True. I understand that's the case because NewType is only examined by the static checker, and ignored at runtime. If I want it to be False, what's ...
user1902689's user avatar
  • 1,675
6 votes
0 answers
121 views

Comfortable way to use strong types instead of bools for parameter flags?

Suppose you have a function that takes a boolean argument: void do_something(bool use_some_option); This has issues because on the call site, you see something like do_something(false) which is not ...
Henk's user avatar
  • 836
1 vote
1 answer
2k views

How to have TypeScript generic function with type argument being keyof an object have return type of that object's key's value

I have a several object types: type Slave = { myKey:string } type AnotherSlave = { anotherKey:string } And a master type that contains some keys, and these object types as those keys' values as ...
Can Poyrazoğlu's user avatar
0 votes
1 answer
701 views

Method pow does not exist error Pyspark error

This is a bit strange. When I create a dataframe and then do some transformations with the function pow, it works. But when I push it to run in a real world scenario, it does not. The datatype of ...
Saugat Mukherjee's user avatar
0 votes
1 answer
186 views

Describing complex return type of the method

I'm trying to define return type of the method in Python (3.8.9). Ideally, return type should be list of tuple of int. My first natural solution, as I came from strongly typed world, was def .... ->...
Daniil T.'s user avatar
  • 1,155
1 vote
1 answer
1k views

Why does TypeScript's Omit not enforce the value of the omitted properties?

Background: (can be skipped) I was fiddling around to make some update(person: Person) statement more usable by allowing a subset of properties it should update. I was thinking there are 2 options: ...
Mike de Klerk's user avatar
0 votes
1 answer
3k views

"Bad return type in lambda expression: String cannot be converted to void" in .forEach method

I have a class Users with, among others, a List of user objects, the following method, which is supposed to build a list of String check if an incoming String is contained in that list. public class ...
LeperAffinity666's user avatar
0 votes
0 answers
77 views

Why sometime I need to explicitly specific the generic type when calling constructor/function in C#?

Refer to the image above, we can see the AbpAsyncDeterminiationInterceptor must have a generic type which is the same as what is provided into its constructor. Supposed it should be interpreted ...
mannok's user avatar
  • 1,732
5 votes
2 answers
2k views

Is there a way in TypeScript to say "Include" (opposite of Exclude)?

I have a String Union that looks like: type AlphabetLike = 'a' | 'b' | 'c' | 'zeta' | 'beta' | 'gamma' | 'mu'; I want to be able to construct the type type Alphabet = 'a' | 'b' | 'c'. I could do this ...
William Neely's user avatar
0 votes
1 answer
357 views

TS2339: Property 'data' does not exist

I have this angular store configuration action.ts export const saveUserAction = createAction( '[User] Save', props<{ payload: User }> ); export const saveUserSuccessAction = ...
Navigator's user avatar
  • 2,901
31 votes
7 answers
14k views

Angular 14 strictly typed reactive forms - How to type FormGroup model using existing interface

I'm just playing around with new angular typed forms api and couldn't figure out how to type FormGroup without declaring specific "FormInterface" witch has to match the original one. Maybe I'...
hawlikus's user avatar
  • 361
1 vote
1 answer
212 views

Omitting keys of a particular type

Here is what I would like: const a = getNumber({a: 3, b: "three"}, "a"); // a is type of number (or even 3) const b = getNumber({a: 3, b: "three"}, "b"); // ...
Michael Lorton's user avatar
0 votes
1 answer
592 views

Defining a method that is strongly typed and allows only inherited types

I want to define a method for a class Dev that must be strongly typed and allows only types inherited from the class Dev that uses a constructor with no parameter. The following is what I came up with:...
dnaiel's user avatar
  • 407
0 votes
0 answers
111 views

Strongly Typed IDs and JSON Schema generation in C#

I like the idea of Strongly Typed IDs and I am using it for some time. I use it also in DTOs without and major problems... till now. I have a use case where I need to generate JSON Schema from some ...
Rok's user avatar
  • 521
1 vote
2 answers
61 views

Java: casting primitive wrappers classes

I have following method that I use when traversing values in JSON document: protected static <T> T getValueAs(Object untypedValue, Class<T> expectedType) { if (expectedType....
kkonrad's user avatar
  • 1,262
1 vote
2 answers
133 views

Using generics, how can I create a tuple of objects from a captured array?

Given a function like this: function makeObjects<T extends string[]>(...values: T); Make the return value this: T.map(v => ({ [v]: any })); I'm using an array map to show what it looks like ...
Swishilicous's user avatar
2 votes
1 answer
637 views

Abstraction - How do I create a generic static method for several types to flow through in Dart/Flutter?

Okay, I'm trying to cut back on an enormous amount of boilerplate code for my app. Right now I see the need for some refactoring and serious abstraction. I want to abstract CRUD actions for my ...
RobbB's user avatar
  • 1,264
1 vote
1 answer
423 views

PHP: Declaring a "numeric" type

With modern versions of PHP, we can declare many different types, union types or even mixed. However, I work with Magento 2, and its often impossible to know if you're going to get an ID of 7 or '7' ...
Tyler V.'s user avatar
  • 2,481
1 vote
1 answer
361 views

Strong types in Protocol Buffers

Since protobuf has no support for type alias is it a valid approach to create a strong type using a message with a single value member like the following? message ID { uint32 value = 1; } message ...
Flauschens's user avatar
1 vote
2 answers
93 views

kotlin get static type of a class property

I'm trying to get the type of some class properties in order to strongly typing my Kotlin Code. In typescript, we can do this (stupid examplebut this is to explain) class Test { private _prop:...
Jerome 's user avatar
  • 2,531
2 votes
1 answer
888 views

Accessing TypeScript Optional Object Properties With a String

I'm working in an existing JavaScript codebase. There is a class which exposes pre-defined functions (e.g. "copy", "paste") for utility. The class can be instantiated with "...
Tanaki's user avatar
  • 2,585
1 vote
0 answers
33 views

Usage of NamedType and type_safe implementations

Recently, there was a talk in my team to use strong types. After a bit of reading different blogs, I am inclined towards avoiding Primitive Obsession and have found below 2 implementations. NamedType ...
talekeDskobeDa's user avatar
0 votes
1 answer
395 views

Typing does not work when creating a map in Kotlin through spring boot @RequestParam

I am using spring boot and have made the following controller where I explicitly specify key and value types. @PostMapping("DAC/set") fun setDac(@RequestParam map: HashMap<Int, Float&...
Anton Kuznetsov's user avatar
1 vote
0 answers
984 views

Make Dictionary<Type, Dictionary<string, object>> strongly-typed

In my application users can search for different things in various places. The same search code could be used for different things. I'm trying to create a cache in order to avoid querying the database ...
Arthur Rey's user avatar
  • 2,990
1 vote
0 answers
383 views

C# Use an undefined number of generic types in the signature of the generic class definition

I was checking in the c# 5,6 specs and is not clear if it is possible use a undefined number of types, such as an array, in the signature of a Generic class definition. As it is very know yu can use ...
Fabio Andrés's user avatar
1 vote
0 answers
263 views

Mypy type narrowing from return values

I'm looking at the following typed Python example: from __future__ import annotations from typing import Optional class Thing: def does_intersect(self, other: Thing) -> bool: return ...
Marcel Besixdouze's user avatar
1 vote
2 answers
2k views

Is it "Pythonic" to type check function arguments? [closed]

Coming from C/C++ background I have always been little set back by the Python's lack of strong type checking. Therefore it always led me to writing code of this style: def function (...
Isla Yoder's user avatar
2 votes
1 answer
111 views

TypeScript Wrapper Function Inferring Types

I use a little utility/wrapper function for functions related to database operations. It should take a specific function fn with the type Promise<PromiseReturnType<GENERIC>>, then do some ...
lsc's user avatar
  • 385
2 votes
1 answer
194 views

Exposing Strongly Typed Ids for Application Commands?

I am using strongly typed ids in my domain model, mostly following the guidance from Andrew Lock at: https://andrewlock.net/using-strongly-typed-entity-ids-to-avoid-primitive-obsession-part-1/ These ...
Neil W's user avatar
  • 8,115
0 votes
1 answer
663 views

How do I emit a signal argument as an int instead of string?

In Godot 3.3, I'm trying to make a Label respond to text entered through a LineEdit node. I connected the objects and can emit the signal, but the signal is only ever sent as a string, not as the int ...
VHS's user avatar
  • 103
1 vote
0 answers
148 views

Strongly-typed reference from input tag-helper

Context Here's an instance of a form tag helper from one of the ASP.NET Core documentation example projects: <form asp-page="./Index" method="get"> <div class="...
dharmatech's user avatar
  • 9,129
0 votes
1 answer
1k views

How to create a `Typed` array in php? [duplicate]

I'd like to do something like that, creating a defined type array of classA inside classB, However, I can't find the syntax. class classA{ } class classB{ private classA $someName:array; }
yossi's user avatar
  • 3,118
0 votes
1 answer
659 views

Angular/Typescript: declare return type of lambda passed to "find"

So, I am following a training course and have an Angular service: import {Exercise} from "./exercise.model"; export class TrainingService{ private availableExercises: Exercise[] = [ { ...
Mawg says reinstate Monica's user avatar
1 vote
0 answers
171 views

Is there a predefined DOM Event object for scroll event?

I'm creating an event handler for a component in Angular. The problem I'm having is right now is: I can't find a typed event for scroll, therefore in the handler's argument I must use any. I see there ...
Nam Le's user avatar
  • 578
1 vote
1 answer
861 views

Typescript: Strong-typing (and autocomplete) for a value based on a sibling object's keys

Say I have an object that looks like this: const configuration: Config = { options: { 'Option 1': 'some value here', 'Option 2': 'some other value here' }, defaultOption: 'Option 1' } ...
Rakesh Pai's user avatar
  • 26.1k
2 votes
1 answer
512 views

Why does annotating this object with a Record type remove Intellisense?

I am creating a data-file that looks like this: interface ISprite { textureName: string, frame: Frame, origin: Vec2, zIndex?: number } export let sprites: Record<string, ISprite> = { ...
Ryan Peschel's user avatar
  • 11.2k

1
2 3 4 5
9