$ Cannot find name 'require'. (2304)
$ npm install @types/node --save-dev可以使用 ts-node 来直接运行 TypeScript 代码:
# Execute a script as you would normally with `node`.
ts-node script.ts
# Starts the TypeScript REPL.
ts-node
# Execute code with TypeScript.
ts-node -e 'console.log("Hello, world!")'
# Execute, and print, code with TypeScript.
ts-node -p '"Hello, world!"'
# Pipe scripts to execute with TypeScript.
echo "console.log('Hello, world!')" | ts-nodeinterface Metadata {
key: string;
value: any;
}
interface MetadataObj {
[key: string]: Metadata;
}
var metadata: MetadataObj = {
// type annotation here is needed
someReducer: { key: 'test', value: 1 },
anotherReducer: { key: 'test', value: 2 } // ...
};
function doSomething(metadata: MetadataObj) {
// ...
}
doSomething(metadata);The property 'MyNamespace' does not exist on value of type 'window' any"
declare global {
interface Window {
MyNamespace: any;
}
}
window.MyNamespace = window.MyNamespace || {};
window['MyNamespace'];
window['get'] = get;
window['get']...