Skip to content

versioning/using-versioned-library error thrown for imports, with no source information #1953

@eddyashton

Description

@eddyashton

I'm trying to split a TypeSpec definition up into multiple files. A small repro is something like this:

// File: bar.tsp
import "@typespec/rest";

@doc(" ")
@TypeSpec.Rest.resource("bazs")
model Baz {
    @doc(" ")
    @visibility("read")
    @key
    id: string;
}

interface Bar {
    @doc(" ")
    getBaz is Azure.Core.StandardResourceOperations.ResourceRead<Baz>;
}
// File: main.tspimport "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "@typespec/rest";

import "./bar.tsp";

@service({
  title: "My Service",
})
@TypeSpec.Versioning.versioned(MyService.Versions)
namespace MyService;

enum Versions {
  @TypeSpec.Versioning.useDependency(Azure.Core.Versions.v1_0_Preview_2)
  `0.0.1-preview`,
}

@TypeSpec.Http.route("/foo")
interface Foo extends Bar {}

This throws the following error during compilation:

TypeSpec compiler v0.44.0

Diagnostics were reported during compilation:

<unknown location>:1:1 - error @typespec/versioning/using-versioned-library: Namespace '' is referencing types from versioned namespace 'Azure.Core' but didn't specify which versions with @useDependency.
> 1 |
    | ^

Found 1 error.

Note the complete lack of source information on the error, making it extremely hard to track down.

It seems the fix is to add namespace MyService to ./bar.tsp as well. EDIT - that's not a viable fix, since it results in all of the imported interfaces also being listed directly at the top-level of the API. So how should we be splitting service definitions up between multiple files?

I think this broke recently? But I could be wrong, maybe I've juggled my files somehow recently.

Regardless, the error message should be improved, as I imagine this is an extremely common error when refactoring code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions