TypeScript のメモ置き場

TypeScritp を書いた時の自分用メモ。
(TypeScript の事はよく分かっていません。。。)
メモなのでかなり雑記

# 変数展開したい

バッククオート(\`)で囲って、展開したいときは `${valname}` という形式で書く

[typescriptで文字列内で変数を展開する](https://blog.mrym.tv/2018/02/typescript%E3%81%A7%E6%96%87%E5%AD%97%E5%88%97%E5%86%85%E3%81%A7%E5%A4%89%E6%95%B0%E3%82%92%E5%B1%95%E9%96%8B%E3%81%99%E3%82%8B/)

# Interface って何？

ここら辺を読んだ

+ [インターフェース ](http://js.studio-kingdom.com/typescript/handbook/interfaces)
+ [Typescriptのinterfaceの使い方](https://qiita.com/nogson/items/86b47ee6947f505f6a7b)
+ [名前空間(namespace)](http://js.studio-kingdom.com/typescript/handbook/namespaces)

今回「Import 先のファイルに指定してある interface を引数とするコンストラクタを使う」という場合で以下のような感じで出来た。

```typescript
import core = require('@aws-cdk/core');
import cognito = require('@aws-cdk/aws-cognito');

export class HelloCdkStack extends core.Stack {
  constructor(scope: core.App, id: string, props?: core.StackProps) {
    super(scope, id, props);

   var myObj:cognito.CfnIdentityPoolRoleAttachment.RoleMappingProperty = {type: 'Token', identityProvider: 'cog
   nito-idp.ap-northeast-1.amazonaws.com/ap-northeast-xxxxx:xxxx', ambiguousRoleResolution: 'AuthenticatedRole'};
    new cognito.CfnIdentityPoolRoleAttachment(this, 'UserPool1RoleMapping', {
            identityPoolId: 'ap-northeast-1:xxx2',
            roles: {
                'authenticated': 'arn:aws:iam::xxxx:role/Cognito_xxxxAuth_Role'
            },
            roleMappings: {
               myObj
            }
    });

  }
}
```

Import 先で設定されている Interface の抜粋

```typescript

export declare namespace CfnIdentityPoolRoleAttachment {
    /**
     * @stability external
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-identitypoolroleattachment-rolemapping.html
     */
    interface RoleMappingProperty {
        /**
         * `CfnIdentityPoolRoleAttachment.RoleMappingProperty.AmbiguousRoleResolution`
         * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-identitypoolroleattachment-rolemapping.html#cfn-cognito-identitypoolroleattachment-rolemapping-ambiguousroleresolution
         */
        readonly ambiguousRoleResolution?: string;
        /**
         * `CfnIdentityPoolRoleAttachment.RoleMappingProperty.IdentityProvider`
         * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-identitypoolroleattachment-rolemapping.html#cfn-cognito-identitypoolroleattachment-rolemapping-identityprovider
         */
        readonly identityProvider?: string;
        /**
         * `CfnIdentityPoolRoleAttachment.RoleMappingProperty.RulesConfiguration`
         * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-identitypoolroleattachment-rolemapping.html#cfn-cognito-identitypoolroleattachment-rolemapping-rulesconfiguration
         */
        readonly rulesConfiguration?: CfnIdentityPoolRoleAttachment.RulesConfigurationTypeProperty | cdk.IResolvable;
        /**
         * `CfnIdentityPoolRoleAttachment.RoleMappingProperty.Type`
         * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-identitypoolroleattachment-rolemapping.html#cfn-cognito-identitypoolroleattachment-rolemapping-type
         */
        readonly type: string;
    }
}
```





# Interface の ? って何？

[Interfaceの使い方(型注釈, implements)](https://www.wakuwakubank.com/posts/636-typescript-interfaces)

? は省略可能という意味らしい
readonly は読み込み専用らしい