microsoft / microsoft/typespec

[Bug]: @typespec/http-client-js | TypeError: Cannot use 'in' operator to search for 'decorators' in undefined

Open
#8,562 0 comments 0 reactions 0 assignees View on GitHub
bug emitter:client:js
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

### Describe the bug

Hello,

I just started playing around with typespec and got this error. It told me to report it so I am, I'm assuming my typespec file should produce errors however the compiler is panicking.

The crash occurs when I add `string` to a union type and generate a js client from it. I do not get an lining errors in my editor or anything like that.

No crash:
```typespec
@discriminated
union Pet {
cat: Cat,
dog: Dog,
}
```

Crash:
```typespec
@discriminated
union Pet {
cat: Cat,
dog: Dog,
string, // this crashes compiler
}
```

### Reproduction

tspconfig.yaml:
```yml
emit:
- "@typespec/http-client-js"
```

main.tsp
```tsp
import "@typespec/http";

using Http;
@service(#{ title: "Widget Service" })
namespace DemoService;

@discriminated
union Pet {
cat: Cat,
dog: Dog,
string, // added, this crashes compiler
}

model Cat {
name: string;
meow: int32;
}

model Dog {
name: string;
bark: string;
}

@error
model Error {
code: int32;
message: string;
}

@route("/widgets")
@tag("Widgets")
interface Widgets {
@get read(@path id: string): Pet | Error;
}
```

terminal output:
```sh
(.venv) ~/t/typespec ❯❯❯ tsp compile . ✘ 1
TypeSpec compiler v1.4.0

✔ Compiling
× Running @typespec/http-client-js...
Emitter "@typespec/http-client-js" crashed! This is a bug.
Please file an issue at https://github.com/microsoft/typespec/issues

TypeError: Cannot use 'in' operator to search for 'decorators' in undefined
at finishType (file:///Users/tharmeyer/tmp/typespec/node_modules/@typespec/compiler/dist/src/core/checker.js:4337:30)
at Object.createLiteralType (file:///Users/tharmeyer/tmp/typespec/node_modules/@typespec/compiler/dist/src/core/checker.js:4537:16)
at Proxy.createString (file:///Users/tharmeyer/tmp/typespec/node_modules/@typespec/compiler/dist/src/typekit/kits/literal.js:8:41)
at Proxy.proxyWrapper (file:///Users/tharmeyer/tmp/typespec/node_modules/@typespec/compiler/dist/src/experimental/typekit/index.js:29:34)
at ObjectEnvelope (file:///Users/tharmeyer/tmp/typespec/node_modules/@typespec/emitter-framework/dist/src/typescript/components/union/expression.js:72:25)
at creator (file:///Users/tharmeyer/tmp/typespec/node_modules/@alloy-js/core/dist/src/runtime/component.js:8:30)
at untrack (file:///Users/tharmeyer/tmp/typespec/node_modules/@alloy-js/core/dist/src/reactivity.js:42:13)
at file:///Users/tharmeyer/tmp/typespec/node_modules/@alloy-js/core/dist/src/render.js:350:37
at vueEffect.scheduler [as fn] (file:///Users/tharmeyer/tmp/typespec/node_modules/@alloy-js/core/dist/src/reactivity.js:79:17)
at ReactiveEffect.run (/Users/tharmeyer/tmp/typespec/node_modules/@vue/reactivity/dist/reactivity.cjs.js:241:19)

--------------------------------------------------
Library Version 0.9.0
TypeSpec Compiler Version 1.4.0
--------------------------------------------------
```

### Checklist

- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/Microsoft/typespec/discussions).
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.