union-types Questions

2

Solved

I'm new to TypeScript and am trying to work with expo-av for audio playback. The following code gives me an error: TS2339: Property 'error' does not exist on type 'AVPlaybackStatus'. const { sound,...
Laylalayman asked 18/2, 2021 at 17:34

7

Solved

For example, I have a type: type abc = 'a' | 'b' | 'c'; How to make a tuple type that contains all elements of the union at compile time? type t = ['a','b', 'c'];
Plerre asked 12/3, 2019 at 17:2

2

Solved

I have a list of interfaces that extends one basic interface. I have also some functions that can accept any of these interfaces. I would like to create a new interface that describe that kind of p...
Scrummage asked 10/2, 2017 at 9:52

1

Solved

I'm trying to model my data in Typescript in the following manner. Main focus is the type MessageHandler that maps the type in a message with a callback that accepts that message. I followed the ha...

4

I get the following errors: type Union = { type: "1"; foo: string } | { type: "2"; bar: number }; function doSomething = (object: Union) => { const { foo } = object // ^ T...
Retrochoir asked 15/1, 2021 at 20:26

2

Solved

Union types, also known as sum types are a powerful language feature that I find myself using often in TypeScript something along the lines of: let a: string | number = “hello” a = 3 How would I a...
Stokeontrent asked 25/6, 2022 at 17:12

4

I've the following struct: type testCase struct { input string isValid bool } I want to use this struct in multiple tests and input could be either a string or an intetc. I can convert the int i...
Macao asked 11/2, 2022 at 12:43

4

Solved

I know I can define string union types to restrict variables to one of the possible string values: type MyType = 'first' | 'second' let myVar:MyType = 'first' I need to construct a type like tha...
Choler asked 22/5, 2019 at 18:50

1

Solved

I want to write a single function that can add certain fields to Firebase message structs. There are two different types of message, Message and MulticastMessage, which both contain Android and APN...
Histogenesis asked 17/6, 2022 at 20:50

2

Solved

If I want to have a type that can be multiple possible types, Unions seem to be how I represent that: U = Union[int, str] U can be an int or a str. I noticed though that TypeVars allow for option...
Substratum asked 17/11, 2019 at 18:42

2

Solved

I have a string literal union type that looks like this: type LowerCaseNames = 'youku-frame' | 'youku' | 'mini-program' | 'tiktok-frame'; This is only an example, since my union type is a list of ...
Trainband asked 4/3, 2022 at 14:17

2

Solved

def func(df_a: pd.DataFrame, df_b: pd.DataFrame) -> (pd.DataFrame, pd.DataFrame): Pylance is advising to modify this line with two solution proposed. What would be the pros and cons of each one...
Arly asked 31/1, 2022 at 16:54

1

So from: export interface Category{ val: string; icon: string } const categoryArray: Category[] = [ { val: 'business', icon: 'store' }, { val: 'media', icon: 'video' }, { val: 'people',...
Wes asked 13/1, 2022 at 13:56

2

Solved

If the members of a union type share a property, and the type of that property can be used to discriminate between those members, I should be able to narrow the type within an if clause using typeo...

3

Solved

Whenever I have to work with objects that have a combined union type, typescript complains about the properties that I try to access and I don't get autocompletion either. For example this: interfa...
Serration asked 15/7, 2020 at 8:8

2

Solved

I wonder whether it's possible to “split” union types into the specific subtypes in TypeScript. This is the code I tried to use, it should be obvious what I'm trying to achieve from the snippet: ty...
Footnote asked 22/10, 2018 at 13:54

0

As far as I can gather, the following two types are equivalent in Python: Optional[Union[A, B]] Union[A, B, None] Is there a defined convention for which one to choose, such as a clause in PE...
Roxannroxanna asked 15/9, 2021 at 0:43

3

Solved

I am writing a type declaration file for a library I do not control. One of the methods accepts an array of strings as a parameter, but these strings can only be very specific values. Currently I a...
Anneliese asked 27/5, 2019 at 15:43

1

Solved

Typed array like $arrIntOnly = [Int[]]@(1, 2, 3) is useful to ensure that all elements are valid type, but is it possible to define multiple types like $arrIntOrString = [[Int | String][]]@(1, &quo...
Vegetate asked 21/7, 2021 at 2:6

3

Solved

Imagine the following simplified setup: import { Action, AnyAction } from 'redux'; // interface Action<Type> { type: Type } and type AnyAction = Action<any> export type FilterActionBy...
Manama asked 27/10, 2019 at 22:57

4

Solved

mypy is really handy and catches a lot of bugs, but when I write "scientific" applications, I often end up doing: def my_func(number: Union[float, int]): # Do something number is either a float...
Caddis asked 19/6, 2018 at 12:33

2

Solved

I'm using typescript on a project and in some parts of it I have to use union types. But I'm getting some weird error messages that I don't know how to deal with. Consider the type below: type body...
Nix asked 9/6, 2021 at 18:10

2

Solved

I've the following tagged union interface interface Example { a: TypeA; b: TypeB; } as an output I would like to convert this tagged union into an union type such as: type oneOf<T> = ... ...
Clypeus asked 26/6, 2020 at 8:49

1

Solved

An example: type TA = {a:number,b:number} type TB = {a:number,c:number,d:number} const t1:Or<TA,TB> = {a:1,b:1} // want const t2:Or<TA,TB> = {a:1,c:1,d:1} // want const t3:Or<...
Corsair asked 26/2, 2021 at 9:11

2

Solved

Is it possible to allow an Array or an object that implements ArrayAccess? For example: class Config implements ArrayAccess { ... } class I_Use_A_Config { public function __construct(Array $te...
Nora asked 11/2, 2013 at 5:58

© 2022 - 2024 — McMap. All rights reserved.