All Questions
497
questions
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&...
-3
votes
1
answer
71
views
How do interfaces in Go work when implementing functions with parameters/return values of a generalised type? [closed]
I'm new to Go and a bit confused in how interfaces work when implemented, especially wrt. functions that have parameters. Say I have an interface with function foo that takes in an interface:
type I ...
1
vote
0
answers
37
views
Angular typescript >> Type vs Interface [duplicate]
I encountered an error
Type 'PaginationParams' is not assignable to type 'HttpParams | { [param: string]: string | number | boolean | readonly (string | number | boolean)[]; } | undefined'.
Type '...
0
votes
0
answers
37
views
How to write generic type for types extraction in Typescript
I am trying to extract types based on input type.
My code is:
type ArrayElement<T> = T extends Array<infer U> ? U : never;
interface Field {
key: string;
value: number | string;
...
0
votes
0
answers
29
views
How does variance work when implementing interfaces/type aliases in TypeScript?
I have the following types :
interface Config {
configurable: boolean;
cancelable: boolean;
isUnique: boolean;
}
// Config Subtype
interface EnvironmentConfig extends Config {
runtime:...
0
votes
0
answers
24
views
Typescript: Declare interface with all optional indices accessible by "indexing into"
I want to create an interface that has all the CSS properties as possible indices but it could have none, and I want to "index into" it.
This would be ideal but it is not working:
declare ...
0
votes
1
answer
26
views
How to manage multi-options for interface field?
I have an interface:
export interface StyledTableProps {
$gridTemplateColumns:
| Array<{
min: string;
max: string;
}>
| {
...
1
vote
2
answers
53
views
How to say to typescript: "this two keys on that interface must have the same type"?
First, I created it:
interface SomeInterface{
param1: unknown
callback: (body: unknown)=>void
}
look basic, right?
but I need something a little bit more specific...
what I need is a way to ...
1
vote
0
answers
126
views
Type 'keyof T' cannot be used to index type 'this'
IUser interface:
interface IUser {
username: string;
email: string;
crypto: string;
}
Class User:
class User implements IUser {
private crypto$: string;
constructor(public username: string, ...
0
votes
0
answers
83
views
How can you share Typescript types and JSON schemas between micro-service code repos?
If you have multiple code repositories that rely on shared data types, and you want to ensure each repository stays in sync with each other, what are some of the best options to ensure that you're not ...
0
votes
1
answer
82
views
Is there a good way to make number type fit "method.Call" in golang?
Code Go Playground :
package main
import (
"fmt"
"reflect"
)
func (s StructWithManyMethods) Func1(a int, b uint, c float64) {
fmt.Printf("func:Func1 a:%d b:%d c:%...
2
votes
1
answer
241
views
Typescript get properties of Parent interface from Child interface [duplicate]
very simple question.. yet I dont know. I have following example from code
interface A {
a:string;
}
interface B extends A{
b:string;
}
const b:B = {
a:'a',
b:'b'
}
const a:A = ...
1
vote
0
answers
33
views
Is there a way in TypeScript to have an interface with optional fields that can only be set together? [duplicate]
How can I write a TypeScript interface along the lines of the following:
type FavoriteColorDescription =
| {
color: "Red" | "Blue";
...
0
votes
2
answers
42
views
Is it necessary to define type again in useState if an interface is already used?
Consider this code:
IAppStateProps.ts:
import {INoteProps} from "./INoteProps";
export interface IAppStateProps {
notesData: INoteProps[];
}
then use it here:
useAppState.ts:
import {...
0
votes
0
answers
36
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:...