@@ -260,7 +260,7 @@ func (r resolverQuery) parsePackageJSON(inputPath string) *packageJSON {
260
260
}
261
261
262
262
// Read the "type" field
263
- if typeJSON , _ , ok := getProperty (json , "type" ); ok {
263
+ if typeJSON , typeKeyLoc , ok := getProperty (json , "type" ); ok {
264
264
if typeValue , ok := getString (typeJSON ); ok {
265
265
switch typeValue {
266
266
case "commonjs" :
@@ -276,10 +276,24 @@ func (r resolverQuery) parsePackageJSON(inputPath string) *packageJSON {
276
276
Range : jsonSource .RangeOfString (typeJSON .Loc ),
277
277
}
278
278
default :
279
- r .log .AddWithNotes (logger .Warning , & tracker , jsonSource .RangeOfString (typeJSON .Loc ),
279
+ notes := []logger.MsgData {{Text : "The \" type\" field must be set to either \" commonjs\" or \" module\" ." }}
280
+ kind := logger .Warning
281
+
282
+ // If someone does something like "type": "./index.d.ts" then they
283
+ // likely meant "types" instead of "type". Customize the message
284
+ // for this and hide it if it's inside a published npm package.
285
+ if strings .HasSuffix (typeValue , ".d.ts" ) {
286
+ notes [0 ] = tracker .MsgData (jsonSource .RangeOfString (typeKeyLoc ),
287
+ "TypeScript type declarations use the \" types\" field, not the \" type\" field:" )
288
+ notes [0 ].Location .Suggestion = "\" types\" "
289
+ if helpers .IsInsideNodeModules (jsonSource .KeyPath .Text ) {
290
+ kind = logger .Debug
291
+ }
292
+ }
293
+
294
+ r .log .AddWithNotes (kind , & tracker , jsonSource .RangeOfString (typeJSON .Loc ),
280
295
fmt .Sprintf ("%q is not a valid value for the \" type\" field" , typeValue ),
281
- []logger.MsgData {{Text : "The \" type\" field must be set to either \" commonjs\" or \" module\" ." }},
282
- )
296
+ notes )
283
297
}
284
298
} else {
285
299
r .log .Add (logger .Warning , & tracker , logger.Range {Loc : typeJSON .Loc },
0 commit comments