Skip to content

Typescript definition generation for resources.Resources has a compilation error due to Fn::Transform #27

Description

@remcoabc

Whenever I use the intended AWS type (as described in the readme) it throws the following compilation error:
TS2411: Property '"Fn::Transform"' of type '{ Name: string; Parameters?: { [k: string]: unknown; }; }' is not assignable to string index type '{ Type: string; Properties?: { [k: string]: unknown; }; CreationPolicy?: { [k: string]: unknown; }; DeletionPolicy?: string; DependsOn?: string[]; Metadata?: { [k: string]: unknown; }; UpdatePolicy?: { [k: string]: unknown; }; UpdateReplacePolicy?: string; Condition?: string; }'.

Activity

  1. fredericbarthelet commented on Feb 10, 2021

    @fredericbarthelet
    Contributor

    Hi @remcoabc and thanks for submitting this issue. Could you please provide your serverless.ts file :) ?

  2. remcoabc commented on Feb 10, 2021

    @remcoabc
    Author
    import { AWS } from '@serverless/typescript';
    import { helloWorld } from './functions';
    
    const serverlessConfiguration: AWS = {
      service: 'remco-stage',
      frameworkVersion: '2',
      plugins: [
        'serverless-webpack',
        'serverless-pseudo-parameters',
      ],
      custom: {
        webpack: {
          webpackConfig: './webpack.config.js',
          includeModules: true,
          keepOutputDirectory: true,
        },
      },
      provider: {
        name: 'aws',
        runtime: 'nodejs12.x',
        apiGateway: {
          shouldStartNameWithService: true,
        },
      },
      functions: {
        helloWorld,
      },
    };
    
    module.exports = serverlessConfiguration;

    @fredericbarthelet

  3. fredericbarthelet commented on Feb 14, 2021

    @fredericbarthelet
    Contributor

    Thanks @remcoabc. Your service file looks perfectly fine. Could you share as well your node version and your package.json for better understanding (i'm particulary interested in your TypeScript version). Could you let me know as well your tsconfig.json for typescript specific configuration ? Thanks :)

  4. remcoabc commented on Feb 15, 2021

    @remcoabc
    Author
    "dependencies": {
        "@dazn/lambda-powertools-logger": "^1.28.1",
        "@dazn/lambda-powertools-pattern-basic": "^1.28.1",
        "aws-sdk": "^2.828.0",
        "axios": "^0.21.1",
        "dotenv": "^8.2.0",
        "serverless-pseudo-parameters": "^2.5.0",
        "source-map-support": "^0.5.10",
        "ulid": "^2.3.0"
      },
      "devDependencies": {
        "@aws-sdk/types": "^3.0.0",
        "@serverless/typescript": "^2.23.0",
        "@types/aws-lambda": "^8.10.17",
        "@types/jest": "^26.0.18",
        "@types/node": "^10.12.18",
        "@types/serverless": "^1.72.5",
        "@typescript-eslint/eslint-plugin": "^4.13.0",
        "@typescript-eslint/parser": "^4.13.0",
        "eslint": "^7.17.0",
        "eslint-config-airbnb-base": "^14.2.1",
        "eslint-config-airbnb-typescript": "^12.0.0",
        "eslint-plugin-import": "^2.22.1",
        "fork-ts-checker-webpack-plugin": "^3.0.1",
        "jest": "^26.6.3",
        "serverless": "^2.15.0",
        "serverless-appsync-plugin": "^1.4.0",
        "serverless-export-env": "^1.4.0",
        "serverless-iam-roles-per-function": "^3.0",
        "serverless-manifest-plugin": "^1.0.7",
        "serverless-webpack": "^5.2.0",
        "ts-jest": "^26.4.4",
        "ts-loader": "^5.3.3",
        "ts-node": "^8.10.2",
        "typescript": "^3.9.7",
        "webpack": "^4.29.0",
        "webpack-node-externals": "^1.7.2"
      }

    I am using node version 12.20.1
    @fredericbarthelet

  5. fredericbarthelet commented on Feb 16, 2021

    @fredericbarthelet
    Contributor

    Thanks @remcoabc, can you provide your tsconfig.json as well ? My understanding is that your current configuration checks for dependancies as well.
    You can bypass this behavior in 2 ways :

    • set "skipLibCheck": true in your compilerOptions in tsconfig.json
    • ignore node_modules folder by setting "exclude": ["node_modules/**/*"] in tsconfig.json

    Can you confirm the above solution solves your problem ?

  6. remcoabc commented on Feb 16, 2021

    @remcoabc
    Author

    I have the node_modules folder already ignored as you can see in my tsconfig.json:

    {
      "compilerOptions": {
        "lib": [
          "es5",
          "es2015",
          "es2016",
          "es2017",
          "es2018",
          "es2019",
          "es2020"
        ],
        "removeComments": true,
        "moduleResolution": "node",
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "sourceMap": true,
        "target": "es2017",
        "outDir": "dist",
        "allowSyntheticDefaultImports": true,
        "module": "commonjs",
        "esModuleInterop": true,
        "resolveJsonModule": true
      },
      "include": ["./**/*.ts", "./**/*.js"],
      "exclude": [
        "node_modules/**/*",
        ".serverless/**/*",
        ".webpack/**/*",
        "_warmup/**/*",
        ".vscode/**/*",
        "dist/**/*"
      ]
    }
  7. grimm2x commented on Feb 16, 2021

    @grimm2x

    I had the same issue. Updated the AWS.resources.Resources type with ( | ) to resolve it:

        Resources?: ({
          "Fn::Transform"?: {
            ...
          };
        } | {
          [k: string]: {
            ...
          };
        });
  8. remcoabc commented on Feb 16, 2021

    @remcoabc
    Author

    I had the same issue. Updated the AWS.resources.Resources type with ( | ) to resolve it:

        Resources?: ({
          "Fn::Transform"?: {
            ...
          };
        } | {
          [k: string]: {
            ...
          };
        });

    This will indeed work if I am able to change the files. Problem is that since I use it in my ci/cd pipeline it will be redownloaded. This means that every change I do to the src code of this library does not have any effect. It would be a solution if that is added in this repo but since the index.d.ts file is auto generated it needs to be fixed somewhere else I think.

  9. grimm2x commented on Feb 16, 2021

    @grimm2x

    This will indeed work if I am able to change the files. Problem is that since I use it in my ci/cd pipeline it will be redownloaded. This means that every change I do to the src code of this library does not have any effect. It would be a solution if that is added in this repo but since the index.d.ts file is auto generated it needs to be fixed somewhere else I think.

    Agreed, it needs to be fixed somewhere upstream. Hopefully this hints at what we're seeing. Just a temporary option to keep typing instead of casting as any.

      functions: {
        helloWorld,
      } as any
  10. fredericbarthelet commented on Feb 16, 2021

    @fredericbarthelet
    Contributor

    @grimm2x @remcoabc thanks to both of you for your insights.
    A bit of context concerning the appearance of this issue :

  11. mblpz commented on Feb 22, 2021

    @mblpz

    how/where can i contribute on this issue? aksing because i stumbled upon #12

  12. changed the title [-]index.d.ts is invalid[/-] [+]Typescript definition generation for resources.Resources has a compilation error due to Fn::Transform[/+] on Apr 27, 2021
  13. JustFly1984 commented on Apr 28, 2021

    @JustFly1984

    I've fixed type declarations and created PR #44

  14. fredericbarthelet commented on May 4, 2021

    @fredericbarthelet
    Contributor

    There currently is a PR ongoing in json-schema-to-typescript that will solve this issue. Do not hesitate to upvote :)

    bcherny/json-schema-to-typescript#383

  15. macsj200 commented on Nov 9, 2021

    @macsj200

    I'm still running into this issue on @serverless/typescript version 2.65.0.

    package.json
    {
      "name": "webhooks-serverless",
      "version": "1.0.0",
      "description": "Serverless aws-nodejs-typescript template",
      "main": "serverless.ts",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "engines": {
        "node": ">=14.15.0"
      },
      "dependencies": {
        "@middy/core": "^1.5.2",
        "@middy/http-json-body-parser": "^1.5.2",
        "source-map-support": "^0.5.19"
      },
      "devDependencies": {
        "@serverless/typescript": "^2.65.0",
        "@types/aws-lambda": "^8.10.71",
        "@types/node": "^14.14.25",
        "json-schema-to-ts": "^1.5.0",
        "serverless": "^2.23.0",
        "serverless-webpack": "^5.3.5",
        "ts-loader": "^8.0.15",
        "ts-node": "^9.1.1",
        "tsconfig-paths": "^3.9.0",
        "tsconfig-paths-webpack-plugin": "^3.3.0",
        "typescript": "^4.1.3",
        "webpack": "^5.20.2",
        "webpack-node-externals": "^2.5.2"
      },
      "author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)",
      "license": "MIT"
    }
    tsconfig.json
    {
      "extends": "./tsconfig.paths.json",
      "compilerOptions": {
        "lib": ["ESNext"],
        "moduleResolution": "node",
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "removeComments": true,
        "sourceMap": true,
        "target": "ES2020",
        "outDir": "lib"
      },
      "include": ["src/**/*.ts", "serverless.ts"],
      "exclude": [
        "node_modules/**/*",
        ".serverless/**/*",
        ".webpack/**/*",
        "_warmup/**/*",
        ".vscode/**/*"
      ],
      "ts-node": {
        "require": ["tsconfig-paths/register"]
      }
    }
    Error message
    node_modules/@serverless/typescript/index.d.ts:1268:7 - error TS2411: Property '"Fn::Transform"' of type '{ Name: string; Parameters?: { [k: string]: unknown; }; }' is not assignable to 'string' index type '{ Type: string; Properties?: { [k: string]: unknown; }; CreationPolicy?: { [k: string]: unknown; }; DeletionPolicy?: string; DependsOn?: AwsResourceDependsOn; Metadata?: { [k: string]: unknown; }; UpdatePolicy?: { ...; }; UpdateReplacePolicy?: string; Condition?: string; }'.
    
    1268       "Fn::Transform"?: {
    

    This error disappears if I add "skipLibCheck": true to tsconfig.json but my understanding is that this is not considered best practice. I can use this workaround for now until bcherny/json-schema-to-typescript#383 lands.

  16. Woodz commented on Jan 11, 2022

    @Woodz

    Thanks @remcoabc, can you provide your tsconfig.json as well ? My understanding is that your current configuration checks for dependancies as well. You can bypass this behavior in 2 ways :

    • set "skipLibCheck": true in your compilerOptions in tsconfig.json
    • ignore node_modules folder by setting "exclude": ["node_modules/**/*"] in tsconfig.json

    Can you confirm the above solution solves your problem ?

    For my situation (listed below), I needed to apply both workarounds (i.e. both skipLibCheck and ignore node_modules) to fix this.

    • "serverless": "^2.57.0",
    • "@serverless/typescript": "^2.70.0",
    • "target": "ES2019",
    • "module": "commonjs",
  17. AntonOellerer commented on Oct 31, 2022

    @AntonOellerer

    It seems as if this error is still present when running npx tsc in a fresh instance of a aws-nodejs-typescript template based project

  18. herebebogans commented on Nov 17, 2023

    @herebebogans

    Until / ever this gets fixed another good workaround is to use

    patch-package

    with above

    #27 (comment)

    workaround in your dependent projects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions