I'm learning TypeScript, my development environment is:
- TS v4.7.4
- deno 1.24.2 (release, x86_64-unknown-linux-gnu) as compiler
- JavaScript language version used: ES2016
- Editor: Visual Studio Code
- plugins installed: JavaScript and TypeScript Nightly v4.9, TypeScript Importer v2.0.1, TypeScript Toolbox v0.5.0
I'm following an old tutorial (which uses TS 4.1.3 with node.js and ES5 for JS), and I have a certain questions with this exercise:
- Create
types/AuthTypes.d.tswith this content:
declare module 'AuthTypes' {
export interface User {
email: string
roles: Array<string>
source?: string
}
}
- Create
user.tswith this initial content:
///<reference path = './types/AuthTypes.d.ts'/>
import auth = require('AuthTypes')
let alice: auth.User
alice = {
email: 'alice@snow.com',
roles: ['super_admin'],
source: 'facebook',
amigo: 'chesu'
}
console.log(alice);
I'm getting three error messages from linter:
- Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
- Relative import path "AuthTypes" not prefixed with / or ./ or ../
- Type '{ email: string; roles: string[]; source: string; amigo: string; }' is not assignable to type 'User'. Object literal may only specify known properties, and 'amigo' does not exist in type 'User'.
The third error is expected. So I changed
///<reference path = './types/AuthTypes.d.ts'/>
import auth = require('AuthTypes')
with this line:
import * as auth from './types/AuthTypes.d.ts'
The program is running now with no errors when it should not because the nonexisting property amigo. How should this problem be properly solved?