有没有办法在TypeScript中嵌套类.我想用它们像:
var foo = new Foo();
var bar = new Foo.Bar();
Run Code Online (Sandbox Code Playgroud) 从标准 setPrototypeOf函数的MDN文档 以及非标准属性: __proto__
强烈建议不要改变对象的[[Prototype]],无论如何实现,因为它非常慢并且不可避免地减慢了现代JavaScript实现中后续执行的速度.
使用Function.prototype添加属性是在添加成员函数JavaScript类的方式.然后如下所示:
function Foo(){}
function bar(){}
var foo = new Foo();
// This is bad:
//foo.__proto__.bar = bar;
// But this is okay
Foo.prototype.bar = bar;
// Both cause this to be true:
console.log(foo.__proto__.bar == bar); // true
Run Code Online (Sandbox Code Playgroud)
为什么foo.__proto__.bar = bar;不好?如果它的坏不是Foo.prototype.bar = bar;那么糟糕?
那么为什么会出现这样的警告:它非常缓慢并且不可避免地减慢了现代JavaScript实现中后续执行的速度.当然Foo.prototype.bar = bar;不是那么糟糕.
更新也许通过突变他们意味着重新分配.见接受的答案.
以前我可以这样做:
import foo = require('foo');
Run Code Online (Sandbox Code Playgroud)
但是现在TypeScript(1.5)支持es6模块语法,在ES6模块语法中实现相同的正确方法是什么.
我对定义现有框架(openlayers.d.ts)很感兴趣,但无法弄清楚如何表达OpenLayers.Layer既是OpenLayers.Layer.Markers的类和命名空间这一事实.我相信这使得Markers成为Layer的嵌套类.
用法:
l = new OpenLayers.Layer(...); // this is a base class, never do this
m = new OpenLayers.Layer.Markers(...);
Run Code Online (Sandbox Code Playgroud)
你会如何在打字稿中声明Layer和Markers类?
如果我有一个可能是字符串或布尔值的属性,我该如何定义它:
interface Foo{
bar:string;
bar:boolean;
}
Run Code Online (Sandbox Code Playgroud)
我不想诉诸:
interface Foo{
bar:any;
}
Run Code Online (Sandbox Code Playgroud)
我不认为没有它any.你可以回答以下任何一个:
我现在忽略了一个规范及其可能吗?有这样的计划吗?是否已记录功能请求:http://typescript.codeplex.com/workitem/list/basic?(更新这是您可以在https://typescript.codeplex.com/workitem/1364上投票的问题报告)
我会想象这样的事情:
interface Foo{
bar:string;
bar:boolean;
bar:any;
}
var x:Foo = <any>{};
x.bar="asdf";
x.bar.toUpperCase(); // intellisence only for string
Run Code Online (Sandbox Code Playgroud) 如果我有以下简单的代码段:
<div ng-app="myApp">
<a ng-disabled='true' ng-click="value1=123">click me</a>
<button ng-disabled='true' ng-click="value2=123">click me</button>
=={{value1}}==
=={{value2}}==
</div>
Run Code Online (Sandbox Code Playgroud)
正如您从小提琴中看到的那样:http://jsfiddle.net/basarat/czVPG/该按钮不可点击,并且ng-click(这只是一个jquery on('click',function(){}))不会执行.但它确实执行锚标记.
自从更新到 RXJS 版本 6 以来,我的 WebStorm 编辑器一直在抱怨startWith() 的某些用法,即运算符被标记为deprecated。
您可以在源代码中看到这些方法被标记为已弃用:
对我来说的问题是弃用的警告不一致。有时它会报告不推荐使用的方法,有时则不会。虽然我可以在下面的代码示例中重现警告。它似乎随机发生在我自己的源代码中。
不弃用:
of(false).pipe(startWith(true));
Run Code Online (Sandbox Code Playgroud)
被标记为弃用:
const x: any = true;
of(false).pipe(startWith(x));
Run Code Online (Sandbox Code Playgroud)
所以我担心这些已弃用的警告。弃用消息说要使用scheduled()andconcat()运算符,但这感觉像是startWith().
所以我有点困惑为什么它被弃用,但为什么它有时只被弃用。
我正在尝试使用grunt-gh-pages扩展来提交我的gh-branch.它在本地工作正常但是当我使用TRAVIS-CI时它会失败.它给出以下错误消息 -
Warning: fatal: remote error:
You can't push to git://github.com/tusharmath/tusharm.com.git
Use https://github.com/tusharmath/tusharm.com.git
Use --force to continue.
Run Code Online (Sandbox Code Playgroud)
当我更新repo选项时,我收到以下错误 -
Warning: remote: Anonymous access to tusharmath/tusharm.com.git denied.
fatal: Authentication failed for 'https://github.com/tusharmath/tusharm.com.git/'
Use --force to continue.
Aborted due to warnings.
Run Code Online (Sandbox Code Playgroud)
所以基本上我只想让Travis-ci在我的仓库的gh-pages分支中提交文件.有没有办法做到这一点?
更新.travis.yml解决问题的决赛
language: node_js
node_js:
- '0.11'
before_script:
- git config --global user.email "tusharmath@gmail.com"
- git config --global user.name "Travis-CI"
after_script:
- git config credential.helper "store --file=.git/credentials"
- echo "https://${GH_TOKEN}:@github.com" > .git/credentials
- node ./node_modules/grunt-cli/bin/grunt release
env: …Run Code Online (Sandbox Code Playgroud) 我正在使用 nextjs 和 mui。我在渲染页面时遇到警告。这是我的代码。请帮忙解决问题!!!
\nimport "../styles/globals.scss";\nimport { AppProps } from "next/app";\nimport useGetAuthentication from "../hooks/useGetAuthentication";\nimport States from "../interfaces/states";\nimport STATUS from "../constants/status";\nimport { CssBaseline } from "@mui/material";\nimport { ThemeProvider } from "@mui/material/styles";\nimport theme from "../styles/theme";\nimport Layout from "../layouts/Layout";\nimport Head from "next/head";\nimport * as React from "react";\nimport Login from "../components/Login";\nimport { Box } from "@mui/material";\n\ninterface MyAppProps extends AppProps {\n emotionCache?: EmotionCache;\n}\n\nconst checkStatusCode = (statusCode: number): boolean => {\n return statusCode === STATUS.NOT_FOUND || statusCode === STATUS.INTERNAL_SERVER_ERROR;\n};\n\nfunction App({ Component, pageProps }: AppProps) {\n …Run Code Online (Sandbox Code Playgroud) typescript reactjs material-ui server-side-rendering next.js
根据我对文档的理解(这里和这里),需要引用内存地址才能工作:
const foo = {};
const map = new Map();
map.set(foo,'123'); // Can only be done if memory address of `foo` is known. Any other shimming would require stringification of foo
Run Code Online (Sandbox Code Playgroud)
这是因为JavaScript对象{}键只能是字符串(至少在ES5中).
但是我看到Map垫片可用:https://github.com/zloirock/core-js#map.我尝试阅读源代码,但它过于整齐抽象(内部使用强大的集合,然后再导入10个文件)
请回答以下任何一项
foo以在其上存储一些字符串然后将其用作关键字?typescript ×7
javascript ×5
ecmascript-6 ×2
angularjs ×1
github ×1
github-pages ×1
html ×1
material-ui ×1
next.js ×1
performance ×1
prototype ×1
reactjs ×1
rxjs ×1
travis-ci ×1