keyof ãã¼ã¯ã¼ã key ã¨ãªãã¸ã§ã¯ããåãåãããããã£ã®å¤ãåãåºãé¢æ°ãèãã¾ãã function getProp(obj: {}, key: string) { return obj[key]; } ãã®é¢æ°ä½¿ã£ã¦å¤æ°ã宣è¨ããã¨åæ¨è«ã§ã¯è¿ãå¤ã¯ any ã«ãªã£ã¦ãã¾ãã¾ãã const urara = { age: 15, name: "chiya", }; const a = getProp(urara, 'age'); // any const n = getProp(urara, 'name'); // any ããã¡ããé å¼µã£ã¦åä»ããããã¨æã£ãã obj ã®åãçµããããªãããã§ãã interface Urara { age: number; name: string; } ã§ã¯ key ã®åã¯ï¼ã¨ãªãã¨ä»ã¾ã§ã¯ç´ æ´ã« String Literal ty
{{#tags}}- {{label}}
{{/tags}}