question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Proposal] - Supporting Generic properties in model

See original GitHub issue

Sorry if this is a duplicate.

interface StoreModel<K extends {}> {
  data: K;
  act: Action<StoreModel<K>, void>;
}

function doSomething<K extends {}, S extends StoreModel<K>>(
  s: State<S>,
  a: Actions<S>
) {
  a.act();
  return s.data;
}

According to Typescript, act and data don’t exist on a and s, respectively.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ctrlplusbcommented, Nov 15, 2019

I might have a solution for this. Will keep u posted 👍

1reaction
ae2438commented, Nov 16, 2019

Cheers Sean! Great response time as always 😃

For now I’ve limited the extending functionality to just overriding existing actions, reducing doSomething to just

function doSomething<K extends {}>(
  s: State<StoreModel<K>>,
  a: Actions<StoreModel<K>>
) {
  a.act();
  return s.data;
}

which does the trick but isn’t ideal. The top answer on StackOverflow was an adventure, hopefully you can work that into a solution 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Proposal] Allow generic attributes · Issue #953 · dotnet/roslyn
Suggestion. I suggest that the generic attributes should be supported, including any generic constraints. Usage example: [TypeConverter<X> ...
Read more >
Generic attributes - C# 11.0 draft specifications
This feature specification describes generic attributes, where a generic class may derive from 'System.Attribute'.
Read more >
Type Parameters Proposal
Generic functions may only use operations supported by all the types permitted by the constraint. Using a generic function or type requires ...
Read more >
Re: Generic Property-Value Proposal for Schema.org
I'm less convinced by the argument "generic extension mechanism for properties at the level of schema.org". As you note, using external ...
Read more >
Is there possible to support inheriting from a generic type: ...
Recently, I tried to write a generic class to extend UIViewController and its all subclasses, so I wrote some codes like this:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found