-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A typescript gotcha or two #848
Comments
That code was created by another user in my other lib in this PR, I don't fully understand how it works, there are print screen of usage in the PR. I have had this code in all my other SlickGrid libraries and never had anyone complained about it. I don't fully understand what your problem is, typically the Here's the print screens of that feature in action and again it was created for known interface not dynamic interface like yours. We could change to
Some of the types might be wrong, if you think that something is wrong you can contribute a PR. I basically took all the TS interfaces from my other lib Slickgrid-Universal SlickDataView interface that I created few years ago. The big difference though is that in my other lib, I created the interface by using SlickGrid as a dependency of the project and that mean that I did not have to add typing for any of the SlickDataView internal and private methods, I think the types are ok in general but it's possible that some are wrong (there's a bigger chance being wrong on private or I should say protected methods). SummaryI don't see what is required to be changed, the best would be for you to contribute a PR EDIT for the setFilter(filterFn: (items: TData, args: any) => boolean) { . . . } |
You can bypass the problem by using something like columnDefinitions: Column<DeviceData & { [field: string]: string; }>[]; I just tried it and it works, I think it would be the best option for you because I don't really want to remove the constraint, it will be helpful in most cases when the interface and the field are known and not dynamic, for example in my demo I use the following interface interface ReportItem {
title: string;
duration: number;
cost: number;
percentComplete: number;
start: Date;
finish: Date;
effortDriven: boolean;
} which gives me this nice and awesome use of intellisense |
- `setFilter` had the incorrect type, it should be `filterFn: (item: T, args: any) => boolean` and that is inline with what `filter` callback is defined on MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#parameters
Hey @lupestro, could you explain what's the purpose of using the Is this perhaps just a wrong example where you'd have the indexer but along with it a couple of named properties? Since we do all these acrobatics merely to provide better Intellisense it would be a two-fold sword if you'd get autocompletion on a few named but nevertheless accepting everything else. Imagine the following situation:
You'd expect your In your original example, I'd personally just drop the generic alltogether since it add's no more value. On the other hand, if you're having quite some known props and would only use a handful of dynamic constructed fields, i'd resort to proactively casting these cases to any --> |
in summary
|
Many thanks for the It would be nice to be able to narrow to Objects with named properties. That's kind of what |
Column field values for DataViews with Dynamic content
I have a table whose content is determined at runtime (using metadata loaded from the web) and it appears to be impossible to specify the
field
of a Column for it.I have:
The Column is defined with:
This is over-constrained as it doesn't allow for specifying fields whose names are not known at compile time.
setFilter
The type of the second parameter to
SlickDataView.setFilter()
shouldn't need to be the same type as the first one.It seems like the
filterFn
passed tosetFilter
should take the same parameters asuncompiledFilter
- noteTData[]
vsTData
in the first parameter, and the second parameter, theargs
, should be the same ones passed tosetFilterArgs
. Hence, perhaps, it might be something like:The text was updated successfully, but these errors were encountered: