ts2c icon indicating copy to clipboard operation
ts2c copied to clipboard

Function Parameter Types

Open anthonyjoeseph opened this issue 3 months ago • 4 comments

This doesn't work:

function addThree(num: number): number {
  return num + 3;
}

/* main.ts:1:21: error: ',' expected main.ts:1:29: error: Missing an opening brace - '{ main.ts:1:30: error: Declaration or statement expected */

This does work:

function addThree(num): number {
  return num + 3;
}

Although the output seems to be looking for a parameter type:

int16_t addThree(/* Cannot determine variable type from source null*/ num) { { ...

P.S. This project is so exciting! I was thrilled when I came across it - great work!

anthonyjoeseph avatar Sep 17 '25 13:09 anthonyjoeseph

Hello,

Thanks for your warm words!

Yes I migrated from using Typescript compiler under the hood to a much faster parser named kataw half a year ago and because of that ts2c has “lost” some features it previously had…

On the other hand, current goal is full support of ES3 features as it is stated in the README and even though there is some support of random features from above standards, including ES5, ES6, ES2016 and so on, all the way up to Typescript itself, but all these standards are not currently supported.

andrei-markeev avatar Sep 17 '25 14:09 andrei-markeev

aha OK I understand - it's only meant to be a subset of typescript features, for now

maybe this is separate ticket, but it would be nice if the parser was able to strip function parameter types as though they were comments. Since as it is, this fails the typescript typechecker. But if that's difficult and/or out of scope I understand!

anthonyjoeseph avatar Sep 17 '25 15:09 anthonyjoeseph

Yes the plan is to go incrementally: focus on 100% support of ES3 spec and then build up from there.

P.S. I thought kataw understands type syntax in parameters but apparently it doesn’t. It might also be an easy fix. Maybe I will fix it some time over the weekend. So keeping this open for now. But if it turns out to be too tedious, I’ll drop it in favor of ES3 work.

andrei-markeev avatar Sep 17 '25 15:09 andrei-markeev

also just to mention, when you experiment with ts2c, please give it something concrete. Not just function but also its usage. It infers the types from usage automatically whenever possible.

andrei-markeev avatar Sep 17 '25 15:09 andrei-markeev