All Questions
Tagged with option-type typescript
60
questions
0
votes
1
answer
31
views
Typescript Maybe, error about null not being covered
I don't know how to get rid of this error, and I don't know why it talks about null.
Shouldn't the seo?.breadcrumbs || [] already cover the case where breadcrumbs is null?
However in the Intro Propos, ...
1
vote
1
answer
44
views
Why typescript cannot refer the type in my example correctly?
Considering the code for Option ADT as below (pretty similar to fp-ts Option):
export type Option<A> = Some<A> | None
export interface Some<A> {
_tag: 'Some'
value: A
}
export ...
1
vote
3
answers
56
views
Return type depending on optional generic type Typescript
I made the following function to generate an object (map) [key] : value from an array.
I want to make the value method optional, and in this case just return the item as it is.
Here is my code :
...
0
votes
0
answers
39
views
TypeScript + Property 'nothing' does not exist on type '<T>(x: T)
I'm trying to hone my Typescript monad skills, so I have created a version of the Maybe monad that technically seems to be working at this point, but Typescript is complaining that Property 'nothing' ...
0
votes
1
answer
102
views
TypeScript, keep type information of initial generic union type
According to the following code, is it possible to tell TypeScript to check the "origin" type of a generic union type, even the generic is "lost"?
const justSymbol: unique symbol = ...
0
votes
1
answer
64
views
How can I declare options in a type-safe way, then access the values?
I'm working with a library that provides a deeply optional interface.
type Option = number | {
x?: number;
y?: number;
z?: number;
}
interface Options {
a?: Option;
b?: Option;
c?: Option;...
2
votes
1
answer
70
views
Why can undefined be implicitly returned without an error?
The following example may return a non-number type (undefined)
function foo(x: number): number
{
if (x != 5) { return x+2; }
// undefined returned here
}
var arg = process.argv[2];
...
1
vote
2
answers
101
views
How to properly declare a recursive interface with optional properties of a mapped type
I am trying to implement an interface of the shape of
type someUnion = "foo" | "bar";
interface RecursiveInterface {
a: number;
b: Array<number>;
[key in someUnion]?: ...
1
vote
0
answers
902
views
Mikro-ORM nullable for ManyToMany property PostgreSQL
I'm new to the MikroORM framework and can't seem to figure this one out.
I try to create an object where the roles property on account is optional. There is a @ManyToMany relationship between role and ...
0
votes
1
answer
363
views
Typescript - optional type if generic is not provided
I Would like optionalFields to have type of OptionalFieldsByTopic<Topic> if generic is not provided, otherwise OptionalFieldsByTopic<T>.
Thanks for help in advance.
export interface ...
1
vote
1
answer
386
views
Typescript optional generic with extends
I would like to write generic that is optional (the D in example below) and extends an interface. I can't figure out the syntax.
interface IUpdateItems {
_id: string;
}
export const deleteItem = &...
1
vote
2
answers
117
views
Writing a function to calculate object properties whereas the object includes optional properties
I have a record of data (object-literal), and I need to calculate the average of several of its properties. For example, consider that each record reflects a sample of dog breeds and their weights. We ...
0
votes
1
answer
45
views
Building a custom function for creating a new object as a subset of object properties of any depth: how to deal with missing entries?
Based on this answer, I've built my own custom function that subsets an object, to keep only some of its properties. Problem is, the code breaks if I point to a property that doesn't exist.
...
0
votes
1
answer
831
views
Typescript error object undefined when optional
I'm not a Typescript professional but I'm getting to know a little bit and I thought I was done with the error: "Object is possibly 'undefined'.ts(2532)". But since this afternoon I have ...
0
votes
1
answer
43
views
How to handle defaulted optional fields in an options parameter for a TypeScript class whilst letting user chose provided arguments?
I'm trying to determine how to handle optional fields in an options argument for a TypeScript class whilst only requiring the user of the class to provide only the arguments they need so all other ...