-
-
Notifications
You must be signed in to change notification settings - Fork 84
Support for key in typescript interfaces #1790
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
Comments
Hmm. That kind of opens the door for I can see the benefit, though. Not sure |
It's just so annoying when something looks exactly like a key value pair and the obvious thing doesn't work. |
I know what you mean. I wouldn't be opposed. Presumably you're not proposing "value" for the type tho? Although I think sometimes I find myself wanting that too 😅 |
I would want both key and value.
|
yeah for classes. and you definitely sometimes give both, eg if you want to ensure you don't miss a field on an object literal or something yeah might be tempted to detect if there is default value and let that win if it exists |
I would start with simple key and value and see how it feels. Number of fields with type and value can't be that many. Not being able to use key and value is any interface feels worse. |
What happens with an index signature? interface Foo {
[index: number]: string;
} |
It actually appears to be extremely common in our code base. I did a very quick search for |
I think we'd want nested scopes there: interface Foo {
[index: number]: string;
//!1 ^^^^^
//!1 -------------
//!2 ^^^^^^^^^^^^^^^
//!2 ------------------------
} |
Well we mostly use classes for targets and there we have a common base. I don't know if I ever used both type and default value outside of cursorless. |
At my work default values for class fields is a common pattern. |
Of course, but that is not what I said. Field with type and default value is unnecessary since the type is derived from the default value. |
Probably should just do this for interface and skip class fields. For we have the same problem with |
Last question from me: how about type aliases and object types? type Foo = {
bar: string,
};
function baz(opts: {
bang: number,
}) {
let whyWouldYouDoThis: {
bloop: Foo,
};
}
const destructure = ({ quux, isFoo }: {
quux: string,
isFoo: boolean,
}) => {} |
That's reasonable, tho I might argue we should just apply the same logic there and allow "value" for "type" when there's no value. But I'm fine starting with just disallowing it for class fields and seeing how annoying it is |
It is sometimes necessary, because typescript can't always infer exactly what type you want from the value itself |
I'd say those should get the same treatment as interfaces |
I know that's why I said that it can't be that many; it is used but it's not too common. I think we should try to optimize for the common use cases with Cursorless. If you make things too complicated it will be hard to remember the rules. Personally I wonder if we should introduce scopes that are just left and right without these kind of nuances. |
agree |
Either way I think for now starting by leaving out classes is probably ok. I think the place where it blurs a bit is abstract classes, which can feel more like an interface, but we can see how annoying the inconsistency is Fwiw tho I don't think it will be too hard to implement the heuristic of letting default value take precedence for "value". If the default value is marked by a field you can just use |
Fixes #1790 ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
value
here can be referred to asname
, but notkey
. I would like to support both.@pokey what do you think?
The text was updated successfully, but these errors were encountered: