449 questions
1
vote
1
answer
39
views
Typescript: is it possible to use a dynamic lookup type in a react component
I made a React component with the following props:
interface Props<TData> {
data: TData;
idField: keyof TData;
onClick: (id: TData[Props<TData>['idField']]) => void; // 'id' ...
0
votes
0
answers
99
views
How to implement the newtype pattern in Julia?
This concept has a several different possible names which might be used to describe the concept.
"Newtype" usually specifically refers to the implementation of the strong type pattern in a ...
0
votes
2
answers
246
views
How do you write a typed nil in Swift?
I have a situation where I have to return a typed nil.
The only way I know of to "make" a typed nil is ..
// need to return String nil
var x: String? = nil
return x
..
// need to return ...
0
votes
1
answer
381
views
Strongly Typed Ids in ASP.Net Core 7
I recently started diving deeper into the Clean Architecture realm with the Ardalis project template. Here is a link to the nuget package to get started with the template.)
I have been reading about ...
0
votes
2
answers
427
views
Type arguments for a method reference can't be inferred from the usage
I'm getting this error in C# on .NET 8.0 (and .NET 6.0 if I'm being pedantic):
Error CS0411: The type arguments for method 'Foo.Execute<I, O>(Func<I, O>)' cannot be inferred from the ...
0
votes
1
answer
63
views
How to enforce variable-types in bash?
I'm trying to create an err function to be used by bash-scripts. The function is supposed to emulate BSD's errx(3) -- printing the specified message and exiting with the code specified as the first ...
1
vote
1
answer
571
views
Troubleshooting foreign key relationships in EF Core with strongly typed IDs in DDD
I'm currently diving into Domain-Driven Design (DDD) and putting it into practice with EF Core. In my domain model, I've opted for strongly typed identifiers. To accommodate this in EF Core, I've ...
5
votes
2
answers
9k
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....
2
votes
0
answers
297
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
1
answer
277
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 ...
3
votes
2
answers
193
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>;
...
0
votes
2
answers
199
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, ...
1
vote
1
answer
191
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 ...
1
vote
1
answer
2k
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?...
1
vote
1
answer
51
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',
}
...