Conversation
Signed-off-by: Lukas Radermacher <[email protected]>
|
I like the idea! However, you might need to allow non- |
|
After looking at For example: import {StrictObject} from "./strict-object";
interface Foo {
a: number;
}
interface Bar extends Foo {
b: number;
}
const c: Bar = {
a: 1,
b: 2,
};
function doSomthingToFoo(bar: Bar): Foo {
return bar;
}
const keys = StrictObject.keys(doSomthingToFoo(c)) satisfies (keyof Foo)[]; // <- incorrect type
console.log(keys) // [ 'a', 'b' ]This compiles without issues but results in unexpected behaviour. |
|
Yes. As described in the doc comment of the |
|
An idea might be to introduce also a |
At least this is the current recommendation of the styleguide: https://github.com/hpi-sam/digital-fuesim-manv/blob/f77dae94c7711fc3908de66bebf7df83d3b32660/README.md?plain=1#L154 My initial intention with this PR was not to introduce new rules but only enforce the existing styleguide with a linter rule, since I noticed many cases where
I would guess that in most cases, it makes sense to use If I think that overall, the benefit of stricter typings outweighs the potential confusion due to type definitions that are to narrow. Without |
I'll look into this |
Do you have an example where this is actually necessary? The examples I tested all infer the types without issues while just using |
The first example I found would be https://github.com/hpi-sam/digital-fuesim-manv/blob/f77dae94c7711fc3908de66bebf7df83d3b32660/shared/src/simulation/activities/count-patients.ts#L65-L69 If we were using In general,
Obviously, there could be a pre-defined array of all possible |
|
(Summary of or in-person discussion from today)
As a refactoring of https://github.com/hpi-sam/digital-fuesim-manv/blob/f77dae94c7711fc3908de66bebf7df83d3b32660/shared/src/simulation/activities/count-patients.ts#L65-L69, one could (as suggested by Felix)
This approach neither requires |
PR Checklist
Please make sure to fulfil the following conditions before marking this PR ready for review:
own code or code licensed under a license compatible to AGPL v3.0 or later, for exceptions look into LICENSE-README.md) and
hereby license the code in this Pull Request under it.
I certify that by signing off my commits (see In case of using third party code, I have given appropriate credit.
We are using DCO for that, see here for more information.