I wanted to share with you an exciting addition to our Functions offering: native support for TypeScript functions!
Up until now, using TypeScript with Netlify Functions involved an additional build step to compile the function code down to JavaScript. As of today, that’s no longer the case. You can simply add a .ts file to your functions directory and our build system handles the rest.
That’s awesome! Thanks team! Out of curiosity, is the backing Github repository meant to be public? Just wanted to check out the type definitions for the event and context objects since I know lots of folks ask for what the shapes of those objects are in various circumstances!
Hi @eduardoboucas,
While everything seems to work seamlessly on production, TS functions are having issues working on netlify-dev, calling function url shows
SyntaxError: Cannot use import statement outside a module
ort { Handler } from '@netlify/functions';
^^^
taxError: Cannot use import statement outside a module
Object.compileFunction (node:vm:355:18)
wrapSafe (node:internal/modules/cjs/loader:1022:15)
Module._compile (node:internal/modules/cjs/loader:1056:27)
Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
Module.load (node:internal/modules/cjs/loader:972:32)
Function.Module._load (node:internal/modules/cjs/loader:813:14)
Module.require (node:internal/modules/cjs/loader:996:19)
require (node:internal/modules/cjs/helpers:92:18)
Object._executeSync (******/node_modules/lambda-local/build/lambdalocal.js:277:26)
Object.execute (******/node_modules/lambda-local/build/lambdalocal.js:83:22)
Can you please try upgrading to version 3.22.0 and seeing if the issue still persists? If so, could you provide a repository with a reproduction case? I’m not able to reproduce this currently.
EDIT: Updated answer to reflect the newly-released version 3.22.0 of the CLI.