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

Ambient types not working for json import assertions with moduleResolution: Node16/NodeNext #51691

Closed
dnalborczyk opened this issue Nov 30, 2022 · 2 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@dnalborczyk
Copy link

Bug Report

πŸ”Ž Search Terms

json import assertions ambient types

⏯ Playground Link

n/a

πŸ’» Code

locationData.json.d.ts

export interface Location {
  id: string
}

declare const locations: Location[]

export default locations

locationData.json

[
  {
    "id": "loc-1"
  }
]

index.ts

import locations from './locationsData.json' assert { type: 'json' }
import type { Location } from './locationsData.json'

tsconfig.json

{
  "compilerOptions": {
    "esModuleInterop": true,
    "module": "ESNext",
    "moduleResolution": "NodeNext",
    "outDir": "dist",
    "strict": true,
    "target": "ESNext",
  },
}

πŸ™ Actual behavior

locations is untyped (any)

πŸ™‚ Expected behavior

locations should be typed

it works as expected with "moduleResolution": "Node"

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Dec 2, 2022
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.0.1 milestone Dec 2, 2022
@fatcerberus
Copy link

Does this even work at all? I thought this required #50133

@weswigham
Copy link
Member

Yep, this never worked - your declaration file is actually for locationsData.json.js, which is commonjs often looks close enough, but in the case of native esm, won't cut it. You need #50133.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

5 participants