Midwest Dev Chat

MidwestDevChat.com

  • The newest 15 messages in the super-cool #typescript channel.

  • 06/11 10:48:09 Nickolas:
  • 06/11 10:48:54 Nickolas: I want to model the response - but the keys in the “attribute” or “normalization” objects can be anything
  • 06/11 10:49:59 Nickolas: I was trying to do this
  • 06/11 10:50:59 Nickolas: is there anyway to model that and let it scale?
  • 06/11 10:51:27 Nickolas: this technically looks like it passes?
      @prop()
      availability: {
        attribute: {
          [name: string]: {
            complete: boolean, values: string[]
          }
        },
        normalization: {
          [name: string]: {
            complete: boolean, values: string[]
          }
        }
      };
    
  • 06/11 10:51:51 Nickolas: did I just answer my own quesiton
  • 06/11 10:52:14 Lida: yeah, I think that’s how I’d model it
  • 06/11 10:54:04 Nickolas: lmfao
  • 06/11 10:54:10 Khalilah: Yep. If you use `[key]: value`, TS will complain that you haven't typed the key. Usually `[key: string]: value` will suffice unless you're doing weird stuff with your keys.
  • 06/11 10:54:29 Lida: like symbols!
  • 06/11 10:55:44 Nickolas: That’s so righteous. Thank you all for being rubber ducks psyduck
  • 06/11 10:57:04 Khalilah: Here's a reference for how to handle dictionaries in the TypeScript docs:
    interface Dictionary<T> {
        [key: string]: T;
    }
    let keys: keyof Dictionary<number>; // string
    let value: Dictionary<number>['foo']; // number
    
    https://www.typescriptlang.org/docs/handbook/ad...
  • 06/11 10:58:51 Khalilah: In your case you already know what the type of your dictionary is so you wouldn't need to make it generic.
  • 06/12 13:01:20 Nickolas: Ohhhhhhh
  • 06/12 13:01:27 Nickolas: Thank you!!!
  • *Usernames have been changed to protect the innocent.
We're currently 1176 members strong. Join us!
Request Invite

Check out all the cool channels!

Join the conversation!