Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error when typing lambda parameters inside constraints #21

Open
ducaale opened this issue Apr 23, 2021 · 1 comment
Open

Syntax error when typing lambda parameters inside constraints #21

ducaale opened this issue Apr 23, 2021 · 1 comment

Comments

@ducaale
Copy link

ducaale commented Apr 23, 2021

In a newly created CRA project, the following code

type NumberContainer = {
  pos: Positive;
}
type Positive = number;

registerType('NumberContainer')

export const x = createValidator<NumberContainer>(undefined, {
  constraints: {
    Positive: (x: Positive) => x > 0
  }
})

Fails with

SyntaxError: /Users/ducaale/lesson-editor/src/lessonValidation.ts: typecheck.macro: /Users/ducaale/lesson-editor/src/lessonValidation.ts: Unexpected token, expected "," (1:3)

> 1 | ((x: Positive) => x > 0)
    |    ^ Learn more: https://www.npmjs.com/package/typecheck.macro
This error occurred during the build time and cannot be dismissed.

Since I have strict mode enabled in my tsconfig.json, I can't leave x untyped and typing it would lead to syntax error from typecheck.macro. My workaround at the moment is to disable ts checking with ts-ignore

export const x = createValidator<NumberContainer>(undefined, {
  constraints: {
    // @ts-ignore
    Positive: x => x > 0
  }
})
@ducaale ducaale changed the title Syntax error when typing lambdas inside constraints Syntax error when typing lambda parameters inside constraints Apr 23, 2021
@ducaale
Copy link
Author

ducaale commented Apr 30, 2021

This seems to be a problem that only happens in create-react-app since I don't get any syntax errors once I eject my app.

Edit: I have opened facebook/create-react-app#10906 regarding this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant