Skip to main content

All Questions

0 votes
0 answers
33 views

Why can't I access a property of an object in a loaded array of objects in typescript?

So, I cannot wrap my mind around this problem... Basically, I have some variables and a constructor in a class: currentUser: UserModel | null = null; currentServer: ServerModel | null = null; ...
btror's user avatar
  • 125
1 vote
0 answers
15 views

Typescript: map nested object properties to string [duplicate]

I am wondering if it is possible to create a type which maps properties of an object to a string where if a certain property value is an object himself, it is added to the string preceded by a dot. ...
asnaeb's user avatar
  • 725
2 votes
1 answer
708 views

typescript access object property: Element implicitly has an 'any' type

I'm working on a codebase where I need to access a value from the step property. interface Car { name: string; age: number; color: string; step: { something: { onea:...
json's user avatar
  • 21
3 votes
2 answers
6k views

Typescript - How to access a variable object property from a variable object

I'm having some difficulty trying to write a function that takes two inputs: The name of an object The name of a property and prints the value of that property for that object. However, the objects ...
rmoreltandem's user avatar
1 vote
2 answers
2k views

TypeScript: Add custom type to a single property in object

Let's say there is an object that looks like this: const object = { prop: "prop", typedProp: "type-1", }; I want the typedProp property to only accept the following values: &...
Dev's user avatar
  • 375
1 vote
1 answer
568 views

Cannot access property of object in an array

Pretty straightforward question, not sure what I've got wrong syntactically here. const options: object[] = [ { value: 0, label: 'Ab' }, { value: 1, label: 'A' }, { value: 2, label: 'Bb' }...
Josh Silveous's user avatar
0 votes
1 answer
57 views

Accessing object property in Typescript using variable

I have following model interface Budget { budget_july?: number, budget_august?: number, budget_september?: number, budget_october?: number, budget_november?: number, ...
thethakuri's user avatar
-1 votes
1 answer
69 views

Typescript - Object display correct datas but properties are undefined on access

When I log the entire object all the datas are displayed but when I try to access the properties they are undefined. As if the object's properties where not mapped to their datas. A component ...
Pouillaude Alexis's user avatar
0 votes
3 answers
462 views

Property 'firstName' does not exist on type 'object'

function marge(obj1: object, obj2: object) { return Object.assign(obj1, obj2); } const margeObj = marge( {firstName: "John"}, {lastName : "Doe"} ); console.log(margeObj....
MD Jahid Hasan's user avatar
1 vote
1 answer
2k views

Dynamically assign property of object with mixed-type properties in TypeScript

Suppose I have an object with some properties that are not all the same type, and I want to assign a dynamic value to a dynamically identified property. This works perfectly fine in JavaScript, but ...
WBT's user avatar
  • 2,415
1 vote
1 answer
2k views

TypeScript copy object's properties to create a new object

I want to create a new object of type 'B' from the object of type 'A' that extends 'B'. I've tried to copy properties of type 'B' from the object with type 'A' and that gives me an error. Could you ...
Maxim Dyuzhinov's user avatar
0 votes
2 answers
7k views

Angular - Property does not exist on type 'Object'

I'm having a few problems with Angular. I'm trying to iterate through a JSON API but I'm receiving the message Property does not exist on type 'Object'. Not exactly that, the error is Property '...
David Encina Martínez's user avatar
1 vote
1 answer
384 views

Assigning TypeScript property values with = vs :

I have the following Angular component: @Component({ ... template: ` <div>{{getDisplayValue(value)}}</div> <button (click)="value= { display: 'one' }">1</button&...
Kyle Vassella's user avatar
0 votes
0 answers
31 views

How to change dynamically the name of a variable in an interface when creating the object?

I'm trying to build an little 2D map editor. My basic map slot is an class with x and y properties. When building the map, a function creates all maps slots according to the requested map size and ...
Kactus83's user avatar
0 votes
1 answer
703 views

How to extract part of the properties' keys of an object as a union type?

In Typescript, I'd like to do the following: Typescript playground type MY_OBJECT = { fooA: string, fooB: string, fooD: string, fooE: string, fooF: string } type SOME_PROPS = Extract<...
cbdeveloper's user avatar
  • 30.4k

15 30 50 per page