N
Nuxt6mo ago
Phillip

How to use DefinitelyTyped types in a Nuxt 3 project?

I've been trying to use DefinitelyTyped types in my project multiple times but just cannot get it working. Is there an additional step that I need to do? 1. installed types for Google Maps with npm i @types/google.maps (https://www.npmjs.com/package/@types/google.maps) 2. in my script setup I try to import an interface like this:
<script setup lang="ts">
import { GeocoderResult } from '@types/google.maps'
<script setup lang="ts">
import { GeocoderResult } from '@types/google.maps'
A index.d.ts is present in @types/google.maps but I'm getting 'GeocoderResult' is declared but its value is never read.ts(6133) Cannot import type declaration files. Consider importing 'google.maps' instead of '@types/google.maps'.ts(6137) Do I need to add something else to my tsconfig? Edit: Okay I just read it's not possible to import index.d.ts file as it seems... but how am I supposed to use the interface in @types/google.maps?
npm
@types/google.maps
TypeScript definitions for google.maps. Latest version: 3.55.11, last published: 12 days ago. Start using @types/google.maps in your project by running npm i @types/google.maps. There are 148 other projects in the npm registry using @types/google.maps.
2 Replies
manniL
manniL6mo ago
does import type { GeocoderResult } from '@types/google.maps' work?
Phillip
PhillipOP6mo ago
Hey @manniL / TheAlexLichter, thanks for your time–I figured it out! Had to reference it:
<script setup lang="ts">
/// <reference types="google.maps" />
<script setup lang="ts">
/// <reference types="google.maps" />
Now I can do this:
const googleAutocompleteCity = (place: google.maps.places.PlaceResult) => {
// yeyyy intellisense, I finally know what's going on :)
const formattedAddress = place.formatted_address
}
const googleAutocompleteCity = (place: google.maps.places.PlaceResult) => {
// yeyyy intellisense, I finally know what's going on :)
const formattedAddress = place.formatted_address
}
Want results from more Discord servers?
Add your server