GoogleFeud / ts-runtime-checks

A typescript transformer that automatically generates validation code from your types.
https://googlefeud.github.io/ts-runtime-checks/
MIT License
312 stars 7 forks source link

[BUG] Narrowing string type to a constant makes compiler fail #23

Closed FredTreg closed 1 year ago

FredTreg commented 1 year ago

Describe the bug Declaring a constant like the following one makes tspc fail:

const PRISMA_ORDERBY = {
  orderBy: { index: 'asc' as 'asc' }
}

The as 'asc' begin the culprit but is required to make the type compatible with what my Prisma code expects in that particular case.

Error:

evalmachine.<anonymous>:118053
              throw e;
              ^

Error: Debug Failure.
    at visitEachChildOfPropertyAssignment (/workspace/coucou/server/node_modules/typescript/lib/typescript.js:87171:19)
    at Object.visitEachChild (/workspace/coucou/server/node_modules/typescript/lib/typescript.js:86171:35)
    at Transformer.visitor (/workspace/coucou/server/node_modules/ts-runtime-checks/dist/transformer.js:197:37)
    at /workspace/coucou/server/node_modules/ts-runtime-checks/dist/transformer.js:197:73
    at visitArrayWorker (/workspace/coucou/server/node_modules/typescript/lib/typescript.js:85983:51)
    at visitNodes2 (/workspace/coucou/server/node_modules/typescript/lib/typescript.js:85954:21)
    at visitEachChildOfObjectLiteralExpression (/workspace/coucou/server/node_modules/typescript/lib/typescript.js:86532:13)
    at Object.visitEachChild (/workspace/coucou/server/node_modules/typescript/lib/typescript.js:86171:35)
    at Transformer.visitor (/workspace/coucou/server/node_modules/ts-runtime-checks/dist/transformer.js:197:37)
    at /workspace/coucou/server/node_modules/ts-runtime-checks/dist/transformer.js:197:73

Node.js v18.12.1

Playground link https://googlefeud.github.io/ts-runtime-checks?code=FAYw9gdgzgLgBABQEoEkDKBZAggfQPJIAiAokgEICacAvHAN7BxxgBOAJgKYtkCeAXPTgBLCJwAeAgOQBDKCElxZcGXIUBfYGqA

Expected behavior Compiler should not break

Additional context Using 0.3.0 There is no 'ts-runtime-checks' code in the code that breaks. Could not find a workaround, reverting to forked 0.1.3...

GoogleFeud commented 1 year ago

Will be fixed tomorrow!

FredTreg commented 1 year ago

Thanks!

Please also check https://googlefeud.github.io/ts-runtime-checks/?code=MYewdgzgLgBNBOMC8MDkBDVN0TleAlmAOZA

Code is similar but outcome is different (compiler does not crash but variable value does not get exported)