Skip to content

Cannot use classes in protos #556

@orgads

Description

@orgads

Environment details

  • Programming language: Typescript
  • OS: Linux
  • Language runtime version: 20
  • Package version: 4.2.0

Steps to reproduce

When esm output is used, the import from protos.js is using import type, and this doesn't allow using the concrete classes in the namespaces, or other values that are not types.

This is example is based on @google-cloud/speech package, in which I only replaced the following line in index.d.ts to import type *...:

import * as protos from '../protos/protos';

Then in my code I have:

import { v1, v1p1beta1, protos as googleProtos } from '@google-cloud/speech';
// An import alias cannot reference a declaration that was imported using 'import type'.ts(1380)
import protos = googleProtos.google.cloud.speech;
function test() {
  // 'protos' cannot be used as a value because it was imported using 'import type'.ts(1361)
  const foo = new protos.v1.SpeechContext();
  // 'protos' cannot be used as a value because it was imported using 'import type'.ts(1361)
  return protos.v1.RecognitionConfig.AudioEncoding.LINEAR16;
}

Is there a reason not to use a simple import instead?

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions