sdedic commented on code in PR #6079: URL: https://github.com/apache/netbeans/pull/6079#discussion_r1238152097
########## java/java.lsp.server/vscode/src/propertiesView/controlTypes.ts: ########## @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +import { EnumType, KeyOfArray, Typed } from "../typesUtil"; + +export type ID = number; + +export const PropTypes: KeyOfArray<PropTypeMap> = [ + "java.lang.String", + "java.lang.Boolean", + "java.util.Properties", + "unknown" +];// unfortunate but necessary duplication +export type PropTypeMap = { + "java.lang.String": string; + "java.lang.Boolean": boolean; + "java.util.Properties": Record<string, string>; + "unknown": unknown +}; +export type Property<T extends keyof PropTypeMap = keyof PropTypeMap> = T extends T ? { + propPref: boolean; + propDispName: string; + propShortName: string; + propWrite: boolean; + propHidden: boolean; + propExpert: boolean; + propType: T; Review Comment: It eventually could, but the typing bound is quite awkward and still requiresa manual reflection-like selection of the correct code path: ``` switch (prop.propType) { case 'java.lang.String': out = makeStringAccess(prop); break; case 'java.lang.Boolean': out = makeBoolAccess(prop); ``` ... instead of ``` function makeStringAccess(prop: Property<'java.lang.String'>) { ``` the function can as well as do ``` function makeStringAccess(prop: Property) { ``` and do `prop.propValue as String` .. without all the fancy, but in effect almost useless constructions. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
