Repository navigation
Typescript definition generation for resources.Resources has a compilation error due to Fn::Transform #27
Description
Activity
Hi @remcoabc and thanks for submitting this issue. Could you please provide your serverless.ts file :) ?
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;
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.jsonfor typescript specific configuration ? Thanks :)"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
@fredericbartheletThanks @remcoabc, can you provide your
tsconfig.jsonas well ? My understanding is that your current configuration checks for dependancies as well.
You can bypass this behavior in 2 ways :- set
"skipLibCheck": truein your compilerOptions intsconfig.json - ignore node_modules folder by setting
"exclude": ["node_modules/**/*"]intsconfig.json
Can you confirm the above solution solves your problem ?
Reacted by wendyliew99, Lucas Barbosa Dias, Venicyus Paz, 0xRoy and Augusto CalacaReacted by Alexey Lyakhov, Gian Franco Zabarino, Mikhail Hozhy, Quentin de Longraye and Rudy Huynh- set
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/**/*" ] }I had the same issue. Updated the AWS.resources.Resources type with ( | ) to resolve it:
Resources?: ({ "Fn::Transform"?: { ... }; } | { [k: string]: { ... }; });
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.
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
@grimm2x @remcoabc thanks to both of you for your insights.
A bit of context concerning the appearance of this issue :-
type checking started failing at release v2.24.0 of serverless with the following addition fix: aws-nodejs-typescript template issue where serverless.ts could not reference type definitions serverless#8929
If you'd like to fix this for the moment, you can revert back to the previoustsconfig.jsonwhereserverless.tsis not part of the included glob pattern -
index.d.tsdoes includes a mistake at the time being. This is due to the wayjson-schema-to-typescripthandlesadditionalPropertiesdefinition from JSON Schema : while this keyword is used to enforce types on properties not defined in the original list of propertiess, TS enforces usage of index signature on all defined properties. This issue is currently under discussion in Broken generation with additionalProperties bcherny/json-schema-to-typescript#356 (comment) - would you want to help infer in the way of generating union types, your help would be greatly appreciated :)
Reacted by Robert Gruner, Alexey Lyakhov, michael trieu and Kubes-
how/where can i contribute on this issue? aksing because i stumbled upon #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 I've fixed type declarations and created PR #44
Reacted by Robert Gruner and Kaio DuarteThere currently is a PR ongoing in
json-schema-to-typescriptthat will solve this issue. Do not hesitate to upvote :)I'm still running into this issue on
@serverless/typescriptversion2.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": truetotsconfig.jsonbut 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.Reacted by Robert GrunerThanks @remcoabc, can you provide your
tsconfig.jsonas well ? My understanding is that your current configuration checks for dependancies as well. You can bypass this behavior in 2 ways :- set
"skipLibCheck": truein your compilerOptions intsconfig.json - ignore node_modules folder by setting
"exclude": ["node_modules/**/*"]intsconfig.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",
Reacted by Anton OellererReacted by Diego Fernando Angel Londono- set
It seems as if this error is still present when running
npx tscin a fresh instance of aaws-nodejs-typescripttemplate based projectReacted by Diego Iglesias, Mikhail Hozhy, Jonathan Lydall, Conner Swann, medv, Felipem, Quentin de Longraye, Chris Feist, Romain Tejero, Arthur and 10 moreUntil / ever this gets fixed another good workaround is to use
with above
workaround in your dependent projects
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; }'.