Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Terry Mun
2018-09-15 11:31:58 +02:00
261 changed files with 6828 additions and 1424 deletions
+6
View File
@@ -1278,6 +1278,12 @@
"sourceRepoURL": "https://github.com/zalmoxisus/redux-devtools-extension",
"asOfVersion": "2.13.2"
},
{
"libraryName": "redux-little-router",
"typingsPackageName": "redux-little-router",
"sourceRepoURL": "https://github.com/FormidableLabs/redux-little-router",
"asOfVersion": "15.1.0"
},
{
"libraryName": "redux-persist",
"typingsPackageName": "redux-persist",
-16
View File
@@ -1,16 +0,0 @@
// Type definitions for react-table-filter 1.0.0
// Project: https://github.com/cheekujha/react-table-filter
// Definitions by: Gnanavel N <https://github.com/gjsln/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from 'react';
export interface TabfilterProps {
rows: string | Array<string> | { [name: string]: boolean; };
onFilterUpdate: (filteredArray: Array<string>, currentFilters: any[]) => any[] | void;
rowClass?: string;
initialFilters?: string | Array<string> | { [name: string]: boolean; };
}
export declare class TableFilter extends React.Component<TabfilterProps> {}
@@ -11,3 +11,7 @@ const test = (levelDown: AbstractLevelDOWN<any, string>) => {
test(new AbstractLevelDOWN('here'));
// $ExpectType void
test(AbstractLevelDOWN('there'));
// $ExpectType void
test(new AbstractLevelDOWN<any, string>('here'));
// $ExpectType void
test(AbstractLevelDOWN<any, string>('there'));
+25 -14
View File
@@ -3,6 +3,7 @@
// Definitions by: Meirion Hughes <https://github.com/MeirionHughes>
// Daniel Byrne <https://github.com/danwbyrne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
export interface AbstractOptions {
readonly [k: string]: any;
@@ -21,7 +22,7 @@ export interface AbstractGetOptions extends AbstractOptions {
asBuffer?: boolean;
}
export interface AbstractLevelDOWN<K, V> extends AbstractOptions {
export interface AbstractLevelDOWN<K = any, V = any> extends AbstractOptions {
open(cb: ErrorCallback): void;
open(options: AbstractOpenOptions, cb: ErrorCallback): void;
@@ -38,17 +39,23 @@ export interface AbstractLevelDOWN<K, V> extends AbstractOptions {
batch(): AbstractChainedBatch<K, V>;
batch(array: ReadonlyArray<AbstractBatch<K, V>>, cb: ErrorCallback): AbstractChainedBatch<K, V>;
batch(array: ReadonlyArray<AbstractBatch<K, V>>, options: AbstractOptions, cb: ErrorCallback): AbstractChainedBatch<K, V>;
batch(
array: ReadonlyArray<AbstractBatch<K, V>>,
options: AbstractOptions,
cb: ErrorCallback,
): AbstractChainedBatch<K, V>;
iterator(options?: AbstractIteratorOptions<K>): AbstractIterator<K, V>;
}
export interface AbstractLevelDOWNConstructor {
new (location: string): AbstractLevelDOWN<any, any>;
(location: string): AbstractLevelDOWN<any, any>;
// tslint:disable-next-line no-unnecessary-generics
new <K = any, V = any>(location: string): AbstractLevelDOWN<K, V>;
// tslint:disable-next-line no-unnecessary-generics
<K = any, V = any>(location: string): AbstractLevelDOWN<K, V>;
}
export interface AbstractIteratorOptions<K> extends AbstractOptions {
export interface AbstractIteratorOptions<K = any> extends AbstractOptions {
gt?: K;
gte?: K;
lt?: K;
@@ -61,20 +68,20 @@ export interface AbstractIteratorOptions<K> extends AbstractOptions {
valueAsBuffer?: boolean;
}
export type AbstractBatch<K, V> = PutBatch<K, V> | DelBatch<K, V>;
export type AbstractBatch<K = any, V = any> = PutBatch<K, V> | DelBatch<K, V>;
export interface PutBatch<K, V> {
export interface PutBatch<K = any, V = any> {
readonly type: 'put';
readonly key: K;
readonly value: V;
}
export interface DelBatch<K, V> {
export interface DelBatch<K = any, V = any> {
readonly type: 'del';
readonly key: K;
}
export interface AbstractChainedBatch<K, V> extends AbstractChainedBatchConstructor, AbstractOptions {
export interface AbstractChainedBatch<K = any, V = any> extends AbstractOptions {
put: (key: K, value: V) => this;
del: (key: K) => this;
clear: () => this;
@@ -83,19 +90,23 @@ export interface AbstractChainedBatch<K, V> extends AbstractChainedBatchConstruc
}
export interface AbstractChainedBatchConstructor {
new(db: any): AbstractChainedBatch<any, any>;
(db: any): AbstractChainedBatch<any, any>;
// tslint:disable-next-line no-unnecessary-generics
new <K = any, V = any>(db: any): AbstractChainedBatch<K, V>;
// tslint:disable-next-line no-unnecessary-generics
<K = any, V = any>(db: any): AbstractChainedBatch<K, V>;
}
export interface AbstractIterator<K, V> extends AbstractChainedBatchConstructor {
export interface AbstractIterator<K, V> extends AbstractOptions {
db: AbstractLevelDOWN<K, V>;
next(cb: ErrorKeyValueCallback<K, V>): this;
end(cb: ErrorCallback): void;
}
export interface AbstractIteratorConstructor {
new(db: any): AbstractIterator<any, any>;
(db: any): AbstractIterator<any, any>;
// tslint:disable-next-line no-unnecessary-generics
new <K = any, V = any>(db: any): AbstractIterator<K, V>;
// tslint:disable-next-line no-unnecessary-generics
<K = any, V = any>(db: any): AbstractIterator<K, V>;
}
export const AbstractLevelDOWN: AbstractLevelDOWNConstructor;
+92 -5
View File
@@ -400,10 +400,10 @@ cognitoUserPoolEvent.request.session![0].challengeName === "DEVICE_SRP_AUTH";
cognitoUserPoolEvent.request.session![0].challengeName === "DEVICE_PASSWORD_VERIFIER";
cognitoUserPoolEvent.request.session![0].challengeName === "ADMIN_NO_SRP_AUTH";
bool = cognitoUserPoolEvent.request.session![0].challengeResult;
strOrUndefined = cognitoUserPoolEvent.request.session![0].challengeMetaData;
strOrUndefined = cognitoUserPoolEvent.request.session![0].challengeMetadata;
strOrUndefined = cognitoUserPoolEvent.request.challengeName;
str = cognitoUserPoolEvent.request.privateChallengeParameters!["answer"];
str = cognitoUserPoolEvent.request.challengeAnswer!["answer"];
str = cognitoUserPoolEvent.request.challengeAnswer!;
boolOrUndefined = cognitoUserPoolEvent.response.answerCorrect;
strOrUndefined = cognitoUserPoolEvent.response.smsMessage;
strOrUndefined = cognitoUserPoolEvent.response.emailMessage;
@@ -413,7 +413,7 @@ boolOrUndefined = cognitoUserPoolEvent.response.issueTokens;
boolOrUndefined = cognitoUserPoolEvent.response.failAuthentication;
str = cognitoUserPoolEvent.response.publicChallengeParameters!["captchaUrl"];
str = cognitoUserPoolEvent.response.privateChallengeParameters!["answer"];
strOrUndefined = cognitoUserPoolEvent.response.challengeMetaData;
strOrUndefined = cognitoUserPoolEvent.response.challengeMetadata;
boolOrUndefined = cognitoUserPoolEvent.response.answerCorrect;
// CloudFormation Custom Resource
@@ -581,7 +581,7 @@ const CodePipelineEvent: AWSLambda.CodePipelineEvent = {
CodePipelineEvent["CodePipeline.job"].data.encryptionKey = { type: 'KMS', id: 'key' };
/* CloudFront events, see http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html */
const CloudFrontRequestEvent: AWSLambda.CloudFrontRequestEvent = {
const CloudFrontRequestWithCustomOriginEvent: AWSLambda.CloudFrontRequestEvent = {
Records: [
{
cf: {
@@ -630,7 +630,44 @@ const CloudFrontRequestEvent: AWSLambda.CloudFrontRequestEvent = {
"TLSv1",
"TLSv1.1"
]
},
}
}
}
}
}
]
};
const CloudFrontRequestWithS3OriginEvent: AWSLambda.CloudFrontRequestEvent = {
Records: [
{
cf: {
config: {
distributionDomainName: "d123.cloudfront.net",
distributionId: "EDFDVBD6EXAMPLE",
eventType: "viewer-request",
requestId: "MRVMF7KydIvxMWfJIglgwHQwZsbG2IhRJ07sn9AkKUFSHS9EXAMPLE=="
},
request: {
clientIp: "2001:0db8:85a3:0:0:8a2e:0370:7334",
method: "GET",
uri: "/picture.jpg",
querystring: "size=large",
headers: {
host: [
{
key: "Host",
value: "d111111abcdef8.cloudfront.net"
}
],
"user-agent": [
{
key: "User-Agent",
value: "curl/7.51.0"
}
]
},
origin: {
s3: {
authMethod: "origin-access-identity",
customHeaders: {
@@ -812,6 +849,56 @@ apiGtwProxyHandler = proxyHandler;
const codePipelineHandler: AWSLambda.CodePipelineHandler = (event: AWSLambda.CodePipelineEvent, context: AWSLambda.Context, cb: AWSLambda.Callback<void>) => {};
const cloudFrontRequestHandler: AWSLambda.CloudFrontRequestHandler = (event: AWSLambda.CloudFrontRequestEvent, context: AWSLambda.Context, cb: AWSLambda.CloudFrontRequestCallback) => {
event = CloudFrontRequestWithCustomOriginEvent;
// $ExpectType CloudFrontRequestEvent
event;
let request = event.Records[0].cf.request;
let s3Origin: AWSLambda.CloudFrontS3Origin = {
authMethod: 'none',
customHeaders: {},
domainName: 'example.com',
path: '/',
region: 'us-east-1'
};
if (request.origin && request.origin.custom) {
request.origin.custom.domainName;
request.origin.custom.domainName = "example2.com";
// $ExpectError
s3Origin = request.origin.s3;
// $ExpectError
request.origin.s3.path = '/';
}
let customOrigin: AWSLambda.CloudFrontCustomOrigin = {
customHeaders: {},
domainName: 'example.com',
keepaliveTimeout: 60,
path: '/',
port: 80,
protocol: 'http',
readTimeout: 30,
sslProtocols: []
};
event = CloudFrontRequestWithS3OriginEvent;
// $ExpectType CloudFrontRequestEvent
event;
request = event.Records[0].cf.request;
if (request.origin && request.origin.s3) {
request.origin.s3.path;
request.origin.s3.path = "/new_path";
// $ExpectError
customOrigin = request.origin.custom;
// $ExpectError
request.origin.custom.path = '/';
}
cb();
cb(null);
cb(new Error(''));
+31 -3
View File
@@ -21,6 +21,7 @@
// Jeremy Nagel <https://github.com/jeznag>
// Louis Larry <https://github.com/louislarry>
// Daniel Papukchiev <https://github.com/dpapukchiev>
// Oliver Hookins <https://github.com/ohookins>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -250,11 +251,11 @@ export interface CognitoUserPoolTriggerEvent {
session?: Array<{
challengeName: "CUSTOM_CHALLENGE" | "PASSWORD_VERIFIER" | "SMS_MFA" | "DEVICE_SRP_AUTH" | "DEVICE_PASSWORD_VERIFIER" | "ADMIN_NO_SRP_AUTH";
challengeResult: boolean;
challengeMetaData?: string;
challengeMetadata?: string;
}>;
challengeName?: string;
privateChallengeParameters?: { [key: string]: string };
challengeAnswer?: { [key: string]: string };
challengeAnswer?: string;
};
response: {
autoConfirmUser?: boolean;
@@ -266,7 +267,7 @@ export interface CognitoUserPoolTriggerEvent {
failAuthentication?: boolean;
publicChallengeParameters?: { [key: string]: string };
privateChallengeParameters?: { [key: string]: string };
challengeMetaData?: string;
challengeMetadata?: string;
answerCorrect?: boolean;
};
}
@@ -561,6 +562,9 @@ export interface CodePipelineEvent {
/**
* CloudFront events
* http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html
* Bear in mind that the "example" event structure in the page above includes
* both an S3 and a Custom origin, which is not strictly allowed. Only one
* of these per event may be present.
*/
export interface CloudFrontHeaders {
[name: string]: Array<{
@@ -569,6 +573,29 @@ export interface CloudFrontHeaders {
}>;
}
export type CloudFrontOrigin =
| { s3: CloudFrontS3Origin, custom?: never }
| { custom: CloudFrontCustomOrigin, s3?: never };
export interface CloudFrontCustomOrigin {
customHeaders: CloudFrontHeaders;
domainName: string;
keepaliveTimeout: number;
path: string;
port: number;
protocol: 'http' | 'https';
readTimeout: number;
sslProtocols: string[];
}
export interface CloudFrontS3Origin {
authMethod: 'origin-access-identity' | 'none';
customHeaders: CloudFrontHeaders;
domainName: string;
path: string;
region: string;
}
export interface CloudFrontResponse {
status: string;
statusDescription: string;
@@ -581,6 +608,7 @@ export interface CloudFrontRequest {
uri: string;
querystring: string;
headers: CloudFrontHeaders;
origin?: CloudFrontOrigin;
}
export interface CloudFrontEvent {
+5 -26
View File
@@ -1,4 +1,3 @@
import bigi = require('bigi');
import bitcoin = require('bitcoinjs-lib');
// For testing only
@@ -8,19 +7,18 @@ function rng() {
// Generate a random bitcoin address
const keyPair1 = bitcoin.ECPair.makeRandom({rng});
const address = keyPair1.getAddress();
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair1.publicKey });
keyPair1.toWIF();
// Generate an address from a SHA256 hash
const hash = bitcoin.crypto.sha256(Buffer.from('correct horse battery staple', 'utf8'));
const d = bigi.fromBuffer(hash);
const keyPair2 = new bitcoin.ECPair(d);
const keyPair2 = bitcoin.ECPair.fromPrivateKey(hash);
// Generate a random keypair for alternative networks
const keyPair3 = bitcoin.ECPair.makeRandom({network: bitcoin.networks.litecoin, rng});
const keyPair3 = bitcoin.ECPair.makeRandom({network: bitcoin.networks.testnet, rng});
keyPair3.toWIF();
keyPair3.getAddress();
const network = keyPair3.getNetwork();
bitcoin.payments.p2pkh({ pubkey: keyPair3.publicKey });
const network = keyPair3.network;
// Test TransactionBuilder and Transaction
const txb = new bitcoin.TransactionBuilder();
@@ -41,22 +39,3 @@ bitcoin.address.toBase58Check(rsBase58Check.hash, rsBase58Check.version);
bitcoin.address.toBech32(rsBech32.data, rsBech32.version, rsBech32.prefix);
bitcoin.address.toOutputScript(address);
bitcoin.address.toOutputScript(address, network);
const redeemScript = bitcoin.script.multisig.output.encode(
2,
[
new Buffer('12345678901234567890123456789012'),
new Buffer('12345678901234567890123456789012'),
new Buffer('12345678901234567890123456789012'),
]
);
bitcoin.script.scriptHash.input.encode(
bitcoin.script.multisig.input.encodeStack(
[
new Buffer('12345678901234567890123456789012'),
new Buffer('12345678901234567890123456789012'),
],
redeemScript,
),
redeemScript,
);
+48 -138
View File
@@ -1,4 +1,4 @@
// Type definitions for bitcoinjs-lib 3.4
// Type definitions for bitcoinjs-lib 4.0
// Project: https://github.com/bitcoinjs/bitcoinjs-lib
// Definitions by: Mohamed Hegazy <https://github.com/mhegazy>
// Daniel <https://github.com/dlebrecht>
@@ -12,8 +12,6 @@
/// <reference types="node" />
import BigInteger = require('bigi');
export interface Out {
script: Buffer;
value: number;
@@ -68,29 +66,23 @@ export class Block {
}
export class ECPair {
constructor(d: BigInteger, Q?: null, options?: { compressed?: boolean, network?: Network });
constructor(d: null | undefined, Q: any, options?: { compressed?: boolean, network?: Network }); // Q should be ECPoint, but not sure how to define such type
d: BigInteger;
readonly compressed: boolean;
readonly privateKey: Buffer;
readonly publicKey: Buffer;
readonly network: Network;
getAddress(): string;
getNetwork(): Network;
getPublicKeyBuffer(): Buffer;
sign(hash: Buffer): ECSignature;
sign(hash: Buffer): Buffer;
toWIF(): string;
verify(hash: Buffer, signature: ECSignature): boolean;
verify(hash: Buffer, signature: Buffer): boolean;
static fromPublicKeyBuffer(buffer: Buffer, network: Network): ECPair;
static fromPrivateKey(buffer: Buffer, options?: { compressed?: boolean, network?: Network }): ECPair;
static fromPublicKey(buffer: Buffer, options?: { compressed?: boolean, network?: Network }): ECPair;
static fromWIF(string: string, network?: Network): ECPair;
@@ -99,66 +91,6 @@ export class ECPair {
export type Rng = (size: number) => Buffer;
export class ECSignature {
constructor(r: BigInteger, s: BigInteger);
toCompact(i: number, compressed: boolean): Buffer;
toDER(): Buffer;
toScriptSignature(hashType: number): Buffer;
static fromDER(buffer: Buffer): ECSignature;
static parseCompact(buffer: Buffer): { compressed: boolean, i: number, signature: ECSignature };
static parseScriptSignature(buffer: Buffer): { signature: ECSignature, hashType: number };
}
export class HDNode {
constructor(keyPair: ECPair, chainCode: Buffer);
keyPair: ECPair;
derive(index: number): HDNode;
deriveHardened(index: number): HDNode;
derivePath(path: string): HDNode;
getAddress(): string;
getFingerprint(): Buffer;
getIdentifier(): Buffer;
getNetwork(): Network;
getPublicKeyBuffer(): Buffer;
isNeutered(): boolean;
neutered(): HDNode;
sign(hash: Buffer): ECSignature;
toBase58(): string;
verify(hash: Buffer, signature: ECSignature): boolean;
static HIGHEST_BIT: number;
static LENGTH: number;
static fromBase58(string: string, networks?: Network[] | Network): HDNode;
static fromSeedBuffer(seed: Buffer, network?: Network): HDNode;
static fromSeedHex(hex: string, network?: Network): HDNode;
static MASTER_SECRET: Buffer;
}
export class Transaction {
version: number;
locktime: number;
@@ -236,9 +168,6 @@ export interface Input {
}
export class TransactionBuilder {
tx: Transaction;
inputs: Input[];
constructor(network?: Network, maximumFeeRate?: number);
addInput(txhash: Buffer | string | Transaction, vout: number, sequence?: number, prevOutScript?: Buffer): number;
@@ -261,7 +190,6 @@ export class TransactionBuilder {
export const networks: {
bitcoin: Network;
litecoin: Network;
testnet: Network;
};
@@ -391,7 +319,7 @@ export namespace address {
/** @since 3.2.0 */
function fromBech32(address: string): { data: Buffer, prefix: string, version: number };
function fromOutputScript(outputScript: Buffer, network?: Network): string;
function fromOutputScript(output: Buffer, network?: Network): string;
function toBase58Check(hash: Buffer, version: number): string;
@@ -401,26 +329,6 @@ export namespace address {
function toOutputScript(address: string, network?: Network): Buffer;
}
export namespace bufferutils {
function pushDataSize(i: number): number;
function readPushDataInt(buffer: Buffer, offset: number): { opcode: number, number: number, size: number };
function readUInt64LE(buffer: Buffer, offset: number): number;
function readVarInt(buffer: Buffer, offset: number): { number: number, size: number };
function varIntBuffer(number: number, buffer: Buffer, offset: number): Buffer;
function varIntSize(number: number): number;
function writePushDataInt(buffer: Buffer, number: number, offset: number): number;
function writeUInt64LE(buffer: Buffer, value: number, offset: number): number;
function writeVarInt(buffer: Buffer, number: number, offset: number): number;
}
export namespace crypto {
function hash160(buffer: Buffer): Buffer;
@@ -449,7 +357,7 @@ export namespace script {
function isCanonicalPubKey(buffer: Buffer): boolean;
function isCanonicalSignature(buffer: Buffer): boolean;
function isCanonicalScriptSignature(buffer: Buffer): boolean;
function isDefinedHashType(hashType: any): boolean;
@@ -465,66 +373,48 @@ export namespace script {
function encode(number: number): Buffer;
}
namespace signature {
function decode(buffer: Buffer): { signature: Buffer, hashType: number };
function encode(signature: Buffer, hashType: number): Buffer;
}
const multisig: {
input: {
check(script: Buffer, allowIncomplete: boolean): boolean;
decode(buffer: Buffer): Array<Buffer | number>;
decodeStack(stack: Buffer[], allowIncomplete: boolean): Array<Buffer | number>;
encode(signatures: Buffer[], scriptPubKey: Buffer): Buffer;
encodeStack(signatures: Buffer[], scriptPubKey: Buffer): Buffer[];
};
output: {
check(script: Buffer, allowIncomplete: boolean): boolean;
decode(buffer: Buffer, allowIncomplete: boolean): { m: number; pubKeys: Array<Buffer | number> };
encode(m: number, pubKeys: Array<Buffer | number>): Buffer;
};
};
const pubKey: {
input: {
check(script: Buffer): boolean;
decode(buffer: Buffer): Array<Buffer | number>;
decodeStack(stack: Buffer[]): Array<Buffer | number>;
encode(signature: Buffer): Buffer;
encodeStack(signature: Buffer): Buffer[];
};
output: {
check(script: Buffer): boolean;
decode(buffer: Buffer): Buffer | number;
encode(pubKey: Buffer): Buffer;
};
};
const pubKeyHash: {
input: {
check(script: Buffer): boolean;
decode(buffer: Buffer): { signature: Buffer; pubKey: Buffer };
decodeStack(stack: Buffer[]): { signature: Buffer; pubKey: Buffer };
encode(signature: Buffer, pubKey: Buffer): Buffer;
encodeStack(signature: Buffer, pubKey: Buffer): [Buffer, Buffer];
};
output: {
check(script: Buffer): boolean;
decode(buffer: Buffer): Buffer;
encode(pubKeyHash: Buffer): Buffer;
};
};
const scriptHash: {
input: {
check(script: Buffer, allowIncomplete: boolean): boolean;
decode(buffer: Buffer): { redeemScriptStack: Buffer[]; redeemScript: Buffer };
decodeStack(stack: Buffer[]): { redeemScriptStack: Buffer[]; redeemScript: Buffer };
encode(redeemScriptSig: Array<Buffer | number>, redeemScript: Buffer): Buffer;
encodeStack(redeemScriptStack: Buffer[], redeemScript: Buffer): Buffer[];
};
output: {
check(script: Buffer): boolean;
decode(buffer: Buffer): Buffer;
encode(scriptHash: Buffer): Buffer;
};
};
@@ -539,36 +429,56 @@ export namespace script {
const witnessPubKeyHash: {
input: {
check(script: Buffer): boolean;
decodeStack(stack: Buffer[]): { signature: Buffer; pubKey: Buffer };
encodeStack(signature: Buffer, pubKey: Buffer): [Buffer, Buffer];
};
output: {
check(script: Buffer): boolean;
decode(buffer: Buffer): Buffer;
encode(pubKeyHash: Buffer): Buffer;
};
};
const witnessScriptHash: {
input: {
check(script: Buffer, allowIncomplete: boolean): boolean;
decodeStack(stack: Buffer[]): { redeemScriptStack: Buffer[]; redeemScript: Buffer };
encodeStack(redeemScriptStack: Buffer[], redeemScript: Buffer): Buffer[];
};
output: {
check(script: Buffer): boolean;
decode(buffer: Buffer): Buffer;
encode(scriptHash: Buffer): Buffer;
};
};
const nullData: {
output: {
check(script: Buffer): boolean;
decode(buffer: Buffer): Buffer;
encode(data: Buffer): Buffer;
};
};
}
export namespace payments {
function p2data(a: { network?: Network, output?: Buffer, data?: Buffer[] }, opts?: { validate?: boolean }):
{ output: Buffer, data: Buffer[] };
function p2ms(a: { network?: Network, m?: number, n?: number, output?: Buffer, pubkeys?: Buffer[], signatures?: Buffer[], input?: Buffer }, opts?: { validate?: boolean }):
{ output: Buffer, m: number, n: number, pubkeys: Buffer[], signatures: Buffer[], input: Buffer, witness: Buffer[] };
function p2pk(a: { input?: Buffer, network?: Network, output?: Buffer, pubkey?: Buffer, signature?: Buffer }, opts?: { validate?: boolean }):
{ output: Buffer, pubkey: Buffer, signature: Buffer, input: Buffer, witness: Buffer[] };
function p2pkh(a: { address?: string, hash?: Buffer, input?: Buffer, network?: Network, output?: Buffer, pubkey?: Buffer, signature?: Buffer }, opts?: { validate?: boolean }):
{ address: string, hash: Buffer, output: Buffer, pubkey: Buffer, signature: Buffer, input: Buffer, witness: Buffer[] };
function p2sh(a: { address?: string, hash?: Buffer, input?: Buffer, network?: Network, output?: Buffer, witness?: Buffer[], redeem?: Redeem }, opts?: { validate?: boolean }):
{ address: string, hash: Buffer, output: Buffer, redeem: Redeem, input: Buffer, witness: Buffer[] };
function p2wpkh(a: { address?: string, hash?: Buffer, input?: Buffer, network?: Network, output?: Buffer, pubkey?: Buffer, signature?: Buffer, witness?: Buffer[] },
opts?: { validate?: boolean }): { address: string, hash: Buffer, output: Buffer, pubkey: Buffer, signature: Buffer, input: Buffer, witness: Buffer[] };
function p2wsh(a: { address?: string, hash?: Buffer, input?: Buffer, network?: Network, output?: Buffer, witness?: Buffer[], redeem?: Redeem }, opts?: { validate?: boolean }):
{ address: string, hash: Buffer, output: Buffer, redeem: Redeem, input: Buffer, witness: Buffer[] };
class Redeem {
input?: Buffer;
network?: Network;
output?: Buffer;
witness?: Buffer[];
}
}
+28
View File
@@ -0,0 +1,28 @@
import BloomFilter = require('bloom-filter');
const numElements = 3;
const falsePositiveRate = 0.01;
const filter = BloomFilter.create(numElements, falsePositiveRate);
// elements
const a = Buffer.from('99108ad8ed9bb6274d3980bab5a85c048f0950c8', 'hex');
const c = Buffer.from('b5a2c786d9ef4658287ced5914b37a1b4aa32eee', 'hex');
// insert elements
// $ExpectType void
filter.insert(a);
// $ExpectType boolean
!filter.contains(c);
// reinstantiate from an object
const serialized = filter.toObject();
const woahFilter = new BloomFilter(serialized);
// initialize directly
const newFilter = new BloomFilter({
vData: Buffer.from('123', 'hex'), // the data of the filter
nHashFuncs: 3, // the number of hash functions to use
nTweak: 2147483649, // the seed used for the hash fuctions
nFlags: 0 // flags used to update the filter when matched
});
+38
View File
@@ -0,0 +1,38 @@
// Type definitions for bloom-filter 0.2
// Project: https://github.com/bitpay/bloom-filter
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
declare class Filter {
constructor(options: Filter.FilterOptions);
static create(elements: number, falsePositiveRate: number, nTweak?: number, nFlags?: number): Filter;
toObject(): Filter.FilterOptions;
hash(nHashNum: number, vDataToHash: Buffer): number;
insert(data: Buffer): void;
contains(data: Buffer): boolean;
clear(): void;
inspect(): string;
BLOOM_UPDATE_NONE: number;
BLOOM_UPDATE_ALL: number;
BLOOM_UPDATE_P2PUBKEY_ONLY: number;
MAX_BLOOM_FILTER_SIZE: number;
MAX_HASH_FUNCS: number;
MIN_HASH_FUNCS: number;
LN2SQUARED: number;
LN2: number;
}
declare namespace Filter {
interface FilterOptions {
vData: Buffer;
nHashFuncs: number;
nTweak?: number;
nFlags?: number;
}
function MurmurHash3(seed: number, data: Buffer): number;
}
export = Filter;
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"bloom-filter-tests.ts"
]
}
+2
View File
@@ -391,6 +391,8 @@ declare namespace Chart {
easing?: string;
onProgress?(chart: any): void;
onComplete?(chart: any): void;
animateRotate?: boolean;
animateScale?: boolean;
}
interface ChartElementsOptions {
@@ -105,15 +105,7 @@ declare const wrongPromise: Promise<number>;
</PromiseSubscription>;
// $ExpectError
const MismatchSubscription = createSubscription({
getCurrentValue: (a: number) => null,
subscribe: (a: string, callback) => (() => undefined)
});
const MismatchSubscription = createSubscription({ getCurrentValue: (a: number) => null, subscribe: (a: string, callback) => (() => undefined) });
// $ExpectError
const NoUnsubscribe = createSubscription({
getCurrentValue: (a: number) => a,
subscribe: (a: number, callback) => {
// oops, should've returned a callback here
}
});
const NoUnsubscribe = createSubscription({ getCurrentValue: (a: number) => a, subscribe: (a: number, callback) => { /* oops, should've returned a callback here */ }});
+47
View File
@@ -0,0 +1,47 @@
import elliptic = require('elliptic');
const ec = new elliptic.ec('secp256k1');
// Generate keys
const key = ec.genKeyPair();
// Sign the message's hash (input must be an array, or a hex-string)
const msgHash = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const signature = key.sign(msgHash);
// Export DER encoded signature in Array
const derSign = signature.toDER();
// Verify signature
console.log(key.verify(msgHash, derSign));
// CHECK WITH NO PRIVATE KEY
const pubPoint = key.getPublic();
const x = pubPoint.getX();
const y = pubPoint.getY();
// Public Key MUST be either:
// 1) '04' + hex string of x + hex string of y; or
// 2) object with two hex string properties (x and y); or
// 3) object with two buffer properties (x and y)
const pub = pubPoint.encode('hex'); // case 1
const aPub = { x: x.toString('hex'), y: y.toString('hex') }; // case 2
const bPub = { x: x.toBuffer(), y: y.toBuffer() }; // case 3
const cPub = { x: x.toArrayLike(Buffer), y: y.toArrayLike(Buffer) }; // case 3
// Import public key
const newKey = ec.keyFromPublic(pub, 'hex');
// Signature MUST be either:
// 1) DER-encoded signature as hex-string; or
// 2) DER-encoded signature as buffer; or
// 3) object with two hex-string properties (r and s); or
// 4) object with two buffer properties (r and s)
// const signature = '3046022100...'; // case 1
// const signature = new Buffer('...'); // case 2
// const signature = { r: 'b1fc...', s: '9c42...' }; // case 3
// Verify signature
console.log(key.verify(msgHash, signature));
+158
View File
@@ -0,0 +1,158 @@
// Type definitions for elliptic 6.4
// Project: https://github.com/indutny/elliptic
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import BN = require('bn.js');
// incomplete typings
export const utils: any;
export const rand: any;
export const eddsa: any;
export type BNInput = string | BN | number | Buffer | number[];
export const version: number;
export namespace curve {
class BaseCurve {
constructor(type: string, conf: BaseCurve.BaseCurveOptions)
p: BN;
type: string;
red: any; // ?
zero: any; // ?
one: any; // ?
two: any; // ?
n: BN | undefined | null;
g: any; // ?
redN: any; // ?
decodePoint(bytes: any, enc: string): any; // ?
}
namespace BaseCurve {
class BasePoint {
constructor(curve: any, type: string);
curve: any;
type: string;
precomputed: PrecomputedValues | null;
encode(enc: string, compact: boolean): BN;
encodeCompressed(enc: string): BN;
validate(): boolean;
precompute(power: number): BasePoint;
dblp(k: any): any; // ?
}
interface BaseCurveOptions {
p: number | string | number[] | Buffer | BN;
prime?: BN | string;
n?: number | BN | Buffer;
g?: any; // ?
gRed?: any; // ?
}
interface PrecomputedValues {
doubles: any; // ?
naf: any; // ?
beta: any; // ?
}
}
}
export namespace curves {
class PresetCurve {
constructor(options: PresetCurve.Options)
type: string;
g: any; // ?
n: BN | undefined | null;
hash: any; // ?
}
namespace PresetCurve {
interface Options {
type: string;
prime: string | null;
p: string;
a: string;
b: string;
n: string;
hash: any;
gRed: boolean;
g: any; // ?
beta?: string;
lambda?: string;
basis?: any; // ?
}
}
}
export class ec {
constructor(options: string | curves.PresetCurve)
curve: any;
n: BN | undefined | null;
nh: any;
g: any;
hash: any;
keyPair(options: ec.KeyPairOptions): ec.KeyPair;
keyFromPrivate(priv: Buffer | ec.KeyPair, enc?: string): ec.KeyPair;
keyFromPublic(pub: Buffer | ec.KeyPair, enc?: string): ec.KeyPair;
genKeyPair(options?: ec.GenKeyPairOptions): ec.KeyPair;
sign(msg: BNInput, key: Buffer | ec.KeyPair, enc: string, options?: ec.SignOptions): ec.Signature;
sign(msg: BNInput, key: Buffer | ec.KeyPair, options?: ec.SignOptions): ec.Signature;
verify(msg: BNInput, signature: ec.Signature | ec.SignatureOptions, key: Buffer | ec.KeyPair, enc?: string): boolean;
recoverPubKey(msg: BNInput, signature: ec.Signature | ec.SignatureOptions, j: number, enc?: string): any;
getKeyRecoveryParam(e: Error | undefined, signature: ec.Signature | ec.SignatureOptions, Q: BN, enc?: string): number;
}
export namespace ec {
interface GenKeyPairOptions {
pers: any;
entropy: any;
persEnc?: string;
entropyEnc?: string;
}
interface SignOptions {
pers: any;
persEnc?: string;
canonical?: boolean;
k?: BN;
}
class KeyPair {
static fromPublic(ec: ec, pub: Buffer | KeyPair, enc?: string): KeyPair;
static fromPrivate(ec: ec, priv: Buffer | KeyPair, enc?: string): KeyPair;
constructor(ec: ec, options: KeyPairOptions)
ec: ec;
validate(): { readonly result: boolean, readonly reason: string };
getPublic(compact: boolean, enc?: string): any; // ?
getPublic(enc?: string): any; // ?
getPrivate(enc?: 'hex'): Buffer | BN | string;
derive(pub: any): any; // ?
sign(msg: BNInput, enc: string, options?: SignOptions): Signature;
sign(msg: BNInput, options?: SignOptions): Signature;
verify(msg: BNInput, signature: Signature | SignatureOptions): boolean;
inspect(): string;
}
class Signature {
constructor(options: SignatureOptions | Signature, enc?: string)
r: BN;
s: BN;
recoveryParam: number | null;
toDER(enc?: string | null): any; // ?
}
interface SignatureOptions {
r: number;
s: number;
recoveryParam?: number;
}
interface KeyPairOptions {
priv?: Buffer;
privEnc?: string;
pub?: Buffer;
pubEnc?: string;
}
}
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"elliptic-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}
+2 -2
View File
@@ -1,5 +1,5 @@
import Application from '@ember/application';
import EmberResolver from 'ember-resolver';
import { Ember } from 'ember';
const MyResolver = EmberResolver.extend({
pluralizedTypes: {
@@ -7,6 +7,6 @@ const MyResolver = EmberResolver.extend({
}
});
const App = Application.extend({
const App = Ember.Application.extend({
Resolver: MyResolver
});
+2 -4
View File
@@ -5,11 +5,9 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
/// <reference types="ember" />
import Resolver from '@ember/application/resolver';
import Ember from 'ember';
/**
* An Ember `Resolver` implementation used by ember-cli.
*/
export default class EmberResolver extends Resolver {}
export default class EmberResolver extends Ember.Resolver {}
@@ -1,4 +1,4 @@
import Application from '@ember/application';
import Ember from 'ember';
import EmberResolver from 'ember-resolver';
const MyResolver = EmberResolver.extend({
@@ -7,6 +7,6 @@ const MyResolver = EmberResolver.extend({
}
});
const App = Application.extend({
const App = Ember.Application.extend({
Resolver: MyResolver
});
+2 -4
View File
@@ -5,11 +5,9 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/// <reference types="ember" />
import Resolver from '@ember/application/resolver';
import Ember from 'ember';
/**
* An Ember `Resolver` implementation used by ember-cli.
*/
export default class EmberResolver extends Resolver {}
export default class EmberResolver extends Ember.Resolver {}
+5
View File
@@ -0,0 +1,5 @@
import Ember from 'ember';
/**
* Ember.Object.extend(...) accepts any number of mixins or literals.
*/
declare type MixinOrLiteral<T, Base> = Ember.Mixin<T, Base> | T;
+28
View File
@@ -0,0 +1,28 @@
/**
* Used to infer the type of ember classes of type `T`.
*
* Generally you would use `EmberClass.create()` instead of `new EmberClass()`.
*
* The single-arg constructor is required by the typescript compiler.
* The multi-arg constructor is included for better ergonomics.
*
* Implementation is carefully chosen for the reasons described in
* https://github.com/typed-ember/ember-typings/pull/29
*/
export type EmberClassConstructor<T> = (new (properties?: object) => T) & (new (...args: any[]) => T);
/**
* Check that any arguments to `create()` match the type's properties.
*
* Accept any additional properties and add merge them into the instance.
*/
export type EmberInstanceArguments<T> = Partial<T> & {
[key: string]: any;
};
/**
* Accept any additional properties and add merge them into the prototype.
*/
export interface EmberClassArguments {
[key: string]: any;
}
+34
View File
@@ -0,0 +1,34 @@
import ComputedProperty from '@ember/object/computed';
/**
* Deconstructs computed properties into the types which would be returned by `.get()`.
*/
export type UnwrapComputedPropertyGetter<T> =
T extends ComputedProperty<infer U, any> ? U :
T;
export type UnwrapComputedPropertyGetters<T> = {
[P in keyof T]: UnwrapComputedPropertyGetter<T[P]>;
};
export type UnwrapComputedPropertySetter<T> =
T extends ComputedProperty<any, infer V> ? V :
T;
export type UnwrapComputedPropertySetters<T> = {
[P in keyof T]: UnwrapComputedPropertySetter<T[P]>;
};
export type ComputedPropertyGetterFunction<T> = (this: any, key: string) => T;
export type ComputedPropertySetterFunction<T> = (this: any, key: string, newVal: T, oldVal: T) => T;
export interface ComputedPropertyGetterObj<T> {
get(this: any, key: string): T;
}
export interface ComputedPropertySetterObj<T> {
set(this: any, key: string, value: T): T;
}
export type ComputedPropertyObj<T> = ComputedPropertyGetterObj<T> | ComputedPropertySetterObj<T> | (ComputedPropertyGetterObj<T> & ComputedPropertySetterObj<T>);
export type ComputedPropertyGetter<T> = ComputedPropertyGetterFunction<T> | ComputedPropertyGetterObj<T>;
export type ComputedPropertySetter<T> = ComputedPropertySetterFunction<T> | ComputedPropertySetterObj<T>;
export type ComputedPropertyCallback<T> = ComputedPropertyGetterFunction<T> | ComputedPropertyObj<T>;
+36
View File
@@ -0,0 +1,36 @@
import { Ember } from "ember";
/**
* Map type `T` to a plain object hash with the identity mapping.
*
* Discards any additional object identity like the ability to `new()` up the class.
* The `new()` capability is added back later by merging `EmberClassConstructor<T>`
*
* Implementation is carefully chosen for the reasons described in
* https://github.com/typed-ember/ember-typings/pull/29
*/
export type Objectify<T> = Readonly<T>;
export type ExtractPropertyNamesOfType<T, S> = {
[K in keyof T]: T[K] extends S ? K : never
}[keyof T];
export type Fix<T> = { [K in keyof T]: T[K] };
export type KeysOfType<Base, Condition> = keyof Pick<Base, {
[Key in keyof Base]: Base[Key] extends Condition ? Key : never
}[keyof Base]>;
export interface TypeLookup {
string: string;
number: number;
boolean: boolean;
regexp: RegExp;
function: (...args: any[]) => any;
array: any[];
error: Error;
filelist: FileList;
class: typeof Ember.Object;
instance: Ember.Object;
date: Date;
null: null;
undefined: undefined;
}
+61 -83
View File
@@ -16,6 +16,16 @@
/// <reference types="handlebars" />
declare module 'ember' {
import {
UnwrapComputedPropertySetters,
UnwrapComputedPropertySetter,
UnwrapComputedPropertyGetters,
UnwrapComputedPropertyGetter,
ComputedPropertyCallback
} from 'ember/-private-types/object/computed';
import { Objectify, Fix, KeysOfType, TypeLookup } from 'ember/-private-types/utils';
import { EmberClassArguments, EmberClassConstructor, EmberInstanceArguments } from 'ember/-private-types/object';
// Capitalization is intentional: this makes it much easier to re-export RSVP on
// the Ember namespace.
import Rsvp from 'rsvp';
@@ -42,51 +52,11 @@ declare module 'ember' {
: F extends (a: infer A, b: infer B, c: infer C, d: infer D, e: infer E) => any
? [A, B, C, D, E]
: never;
/**
* Deconstructs computed properties into the types which would be returned by `.get()`.
*/
type UnwrapComputedPropertyGetter<T> =
T extends Ember.ComputedProperty<infer U, any> ? U :
T;
type UnwrapComputedPropertyGetters<T> = {
[P in keyof T]: UnwrapComputedPropertyGetter<T[P]>;
};
type UnwrapComputedPropertySetter<T> =
T extends Ember.ComputedProperty<any, infer U> ? U :
T;
type UnwrapComputedPropertySetters<T> = {
[P in keyof T]: UnwrapComputedPropertySetter<T[P]>;
};
/**
* Check that any arguments to `create()` match the type's properties.
*
* Accept any additional properties and add merge them into the instance.
*/
type EmberInstanceArguments<T> = Partial<T> & {
[key: string]: any;
};
/**
* Accept any additional properties and add merge them into the prototype.
*/
interface EmberClassArguments {
[key: string]: any;
}
/**
* Map type `T` to a plain object hash with the identity mapping.
*
* Discards any additional object identity like the ability to `new()` up the class.
* The `new()` capability is added back later by merging `EmberClassConstructor<T>`
*
* Implementation is carefully chosen for the reasons described in
* https://github.com/typed-ember/ember-typings/pull/29
*/
type Objectify<T> = Readonly<T>;
type Fix<T> = { [K in keyof T]: T[K] };
type Mix<A, B> = B & Pick<A, Exclude<keyof A, keyof B>>;
type Mix3<A, B, C> = Mix<Mix<A, B>, C>;
type Mix4<A, B, C, D> = Mix3<Mix<A, B>, C, D>;
type Mix5<A, B, C, D, E> = Mix4<Mix<A, B>, C, D, E>;
/**
* Ember.Object.extend(...) accepts any number of mixins or literals.
@@ -104,23 +74,6 @@ declare module 'ember' {
* Implementation is carefully chosen for the reasons described in
* https://github.com/typed-ember/ember-typings/pull/29
*/
type EmberClassConstructor<T> = (new (properties?: object) => T) & (new (...args: any[]) => T);
type ComputedPropertyGetterFunction<T> = (this: any, key: string) => T;
interface ComputedPropertyGet<T> {
get(this: any, key: string): T;
}
interface ComputedPropertySet<T> {
set(this: any, key: string, value: T): T;
}
type ComputedPropertyCallback<T> =
| ComputedPropertyGetterFunction<T>
| ComputedPropertyGet<T>
| ComputedPropertySet<T>
| (ComputedPropertyGet<T> & ComputedPropertySet<T>);
interface ActionsHash {
[index: string]: (...params: any[]) => any;
@@ -143,7 +96,7 @@ declare module 'ember' {
type ObserverMethod<Target, Sender> =
| (keyof Target)
| ((this: Target, sender: Sender, key: keyof Sender, value: any, rev: number) => void);
| ((this: Target, sender: Sender, key: string, value: any, rev: number) => void);
interface RenderOptions {
into?: string;
@@ -786,7 +739,7 @@ declare module 'ember' {
class ContainerDebugAdapter extends Object {
resolver: Resolver;
canCatalogEntriesByType(type: string): boolean;
catalogEntriesByType(type: string): any[];
catalogEntriesByType(type: string): string[];
}
/**
* Additional methods for the Controller.
@@ -1051,32 +1004,54 @@ declare module 'ember' {
* The container-debug-adapter which is used
* to list all models.
*/
containerDebugAdapter: any;
containerDebugAdapter: ContainerDebugAdapter;
/**
* Ember Data > v1.0.0-beta.18
* requires string model names to be passed
* around instead of the actual factories.
*/
acceptsModelName: any;
acceptsModelName: boolean;
/**
* Specifies how records can be filtered.
* Records returned will need to have a `filterValues`
* property with a key for every name in the returned array.
*/
getFilters(): any[];
getFilters(): DataAdapter.Column[];
/**
* Fetch the model types and observe them for changes.
*/
watchModelTypes(typesAdded: Function, typesUpdated: Function): Function;
watchModelTypes(
typesAdded: (types: DataAdapter.WrappedType[]) => void,
typesUpdated: (types: DataAdapter.WrappedType[]) => void
): () => void;
/**
* Fetch the records of a given type and observe them for changes.
*/
watchRecords(
modelName: string,
recordsAdded: Function,
recordsUpdated: Function,
recordsRemoved: Function
): Function;
recordsAdded: (records: DataAdapter.WrappedRecord[]) => void,
recordsUpdated: (records: DataAdapter.WrappedRecord[]) => void,
recordsRemoved: (idx: number, count: number) => void
): () => void;
}
namespace DataAdapter {
interface Column {
name: string;
desc: string;
}
interface WrappedRecord {
columnValues: object;
object: object;
}
interface WrappedType {
type: {
name: string;
count: number;
columns: Column[];
object: typeof Object;
};
release: () => void;
}
}
const Debug: {
/**
@@ -1085,14 +1060,14 @@ declare module 'ember' {
* The following example demonstrates its usage by registering a handler that throws an error if the
* message contains the word "should", otherwise defers to the default handler.
*/
registerDeprecationHandler(handler: Function): any;
registerDeprecationHandler(handler: (message: string, options: { id: string, until: string }, next: () => void) => void): void;
/**
* Allows for runtime registration of handler functions that override the default warning behavior.
* Warnings are invoked by calls made to [Ember.warn](http://emberjs.com/api/classes/Ember.html#method_warn).
* The following example demonstrates its usage by registering a handler that does nothing overriding Ember's
* default warning behavior.
*/
registerWarnHandler(handler: Function): any;
registerWarnHandler(handler: (message: string, options: { id: string }, next: () => void) => void): void;
};
/**
* The DefaultResolver defines the default lookup rules to resolve
@@ -3064,20 +3039,20 @@ declare module 'ember' {
/**
* Run a function meant for debugging.
*/
function runInDebug(func: () => void): any;
function runInDebug(func: () => any): void;
/**
* Display a warning with the provided message.
*/
function warn(message: string, test: boolean, options: { id: string }): any;
function warn(message: string, options: { id: string }): any;
function warn(message: string, test: boolean, options: { id: string }): void;
function warn(message: string, options: { id: string }): void;
/**
* @deprecated Missing deprecation options: https://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options
*/
function warn(message: string, test: boolean, options?: { id?: string }): any;
function warn(message: string, test: boolean, options?: { id?: string }): void;
/**
* @deprecated Missing deprecation options: https://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options
*/
function warn(message: string, options?: { id?: string }): any;
function warn(message: string, options?: { id?: string }): void;
/**
* Global helper method to create a new binding. Just pass the root object
* along with a `to` and `from` path to create and connect the binding.
@@ -3167,7 +3142,7 @@ declare module 'ember' {
* Merge the contents of two objects together into the first object.
* @deprecated Use Object.assign
*/
function merge<T, U>(original: T, updates: U): T & U;
function merge<T extends object, U extends object>(original: T, updates: U): Mix<T, U>;
/**
* Makes a method available via an additional name.
*/
@@ -3311,14 +3286,17 @@ declare module 'ember' {
/**
* Returns a consistent type for the passed object.
*/
function typeOf(item?: any): string;
function typeOf<T>(value: T): KeysOfType<TypeLookup, T>;
function typeOf(): 'undefined';
function typeOf(item: any): string;
/**
* Copy properties from a source object to a target object.
* @deprecated Use Object.assign
*/
function assign<T, U>(target: T, source: U): T & U;
function assign<T, U, V>(target: T, source1: U, source2: V): T & U & V;
function assign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
function assign<T extends object, U extends object>(target: T, source: U): Mix<T, U>;
function assign<T extends object, U extends object, V extends object>(target: T, source1: U, source2: V): Mix3<T, U, V>;
function assign<T extends object, U extends object, V extends object, W extends object>(target: T, source1: U, source2: V, source3: W): Mix4<T, U, V, W>;
/**
* Polyfill for Object.create
* @deprecated Use Object.create
+7
View File
@@ -1,3 +1,7 @@
/**
* Tests to ensure that access modifier keywords are appropriately
* respected and supported
*/
import Ember from 'ember';
import { assertType } from './lib/assert';
@@ -8,13 +12,16 @@ class Foo extends Ember.Object {
}
const f = new Foo();
assertType<string>(f.hello());
// protected property should not be visible from outside of Foo
assertType<string>(f.bar()); // $ExpectError
// private property should not be visible from outside of Foo
assertType<string>(f.baz()); // $ExpectError
class Foo2 extends Ember.Object.extend({
bar: ''
}) {
hello() { return 'world'; }
// Cannot override with a mis-matched property type
protected bar() { return 'bar'; } // $ExpectError
private baz() { return 'baz'; }
}
+3
View File
@@ -3,6 +3,9 @@ import Component from '@ember/component';
import Object, { computed } from '@ember/object';
import hbs from 'htmlbars-inline-precompile';
import { assertType } from "./lib/assert";
import ComputedProperty from '@ember/object/computed';
import { ExtractPropertyNamesOfType } from 'ember/-private-types/utils';
import { UnwrapComputedPropertySetter } from 'ember/-private-types/object/computed';
Component.extend({
layout: hbs`
+198
View File
@@ -0,0 +1,198 @@
import Ember from 'ember';
import { assertType } from './lib/assert';
/** Newable tests */
const co1 = new Ember.CoreObject();
// TODO: Enable in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
// co1.concatenatedProperties; // $ExpectType string[]
co1.isDestroyed; // $ExpectType boolean
co1.isDestroying; // $ExpectType boolean
co1.destroy(); // $ExpectType CoreObject
co1.toString(); // $ExpectType string
/** .create tests */
const co2 = Ember.CoreObject.create();
// TODO: Enable in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
// co2.concatenatedProperties; // $ExpectType string[]
co2.isDestroyed; // $ExpectType boolean
co2.isDestroying; // $ExpectType boolean
co2.destroy(); // $ExpectType CoreObject
co2.toString(); // $ExpectType string
/** .create tests w/ initial instance data passed in */
const co3 = Ember.CoreObject.create({ foo: '123', bar: 456 });
co3.foo; // $ExpectType string
co3.bar; // $ExpectType number
/** .extend with a zero-argument .create() */
const co4 = Ember.CoreObject.extend({
foo: '123',
bar: 456,
baz(): [string, number] {
return [this.foo, this.bar];
}
}).create();
co4.foo; // $ExpectType string
co4.bar; // $ExpectType number
co4.baz; // $ExpectType () => [string, number]
/** .extend with inconsistent arguments passed into .create() */
const class05 = Ember.CoreObject.extend({
foo: '123' as (string | boolean),
bar: 456,
baz() {
return [this.foo, this.bar];
}
});
const c05 = class05.create({ foo: 99 }); // $ExpectError
const c05b = class05.create({ foo: true });
const c05c = class05.create({ foo: 'abc' });
assertType<string>(c05b.foo); // $ExpectError
assertType<boolean>(c05c.foo); // $ExpectError
/** two .extend arguments with a zero-argument .create() */
const co6 = Ember.CoreObject.extend({
foo: '123',
bar: 456,
baz() {
return [this.foo, this.bar];
},
func1() {
// this includes stuff from CoreObject
this.init; // $ExpectType () => void
// this includes stuff from this extend-arg
this.foo; // $ExpectType string
// this does not include stuff from later extend args
this.bee; // $ExpectError
}
}, {
foo: 99,
bee: 'honey',
func2() {
// this includes stuff from CoreObject
this.init; // $ExpectType () => void
// this includes stuff from this extend-arg
// TODO: switch to "$ExpectType number" in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
this.foo; // $ExpectType string & number
// this includes stuff from earlier extend-args
this.bar; // $ExpectType number
}
}).create();
// TODO: enable in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
// assertType<string>(co6.foo); // $ExpectError
assertType<number>(co6.bar); // $ExpectType number
assertType<() => Array<string | number>>(co6.baz); // $ExpectType () => (string | number)[]
/** three .extend arguments with a zero-argument .create() */
const co7 = Ember.CoreObject.extend({
foo: '123',
bar: 456,
baz() {
return [this.foo, this.bar];
},
func1() {
// this includes stuff from CoreObject
this.init; // $ExpectType () => void
// this includes stuff from this extend-arg
this.foo; // $ExpectType string
// this does not include stuff from later extend args
this.bee; // $ExpectError
}
}, {
foo: 99,
bee: 'honey',
func2() {
// this includes stuff from CoreObject
this.init; // $ExpectType () => void
// this includes stuff from this extend-arg
// TODO: switch to "$ExpectType number" in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
this.foo; // $ExpectType string & number
// this includes stuff from earlier extend-args
this.bar; // $ExpectType number
}
}, {
foo: '99',
money: 'in the banana stand',
func3() {
// this includes stuff from CoreObject
this.init; // $ExpectType () => void
// this includes stuff from this extend-arg
this.money; // $ExpectType string
// this includes stuff from earlier extend-args
this.bee; // $ExpectType string
this.bar; // $ExpectType number
}
}).create();
// TODO: enable in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
// assertType<number>(co7.foo); // $ExpectError
assertType<number>(co7.bar); // $ExpectType number
assertType<string>(co7.money); // $ExpectType string
assertType<() => Array<string | number>>(co7.baz); // $ExpectType () => (string | number)[]
/** four .extend arguments with a zero-argument .create() */
const co8 = Ember.CoreObject.extend({
foo: '123',
bar: 456,
baz() {
return [this.foo, this.bar];
},
func1() {
// this includes stuff from CoreObject
this.init; // $ExpectType () => void
// this includes stuff from this extend-arg
this.foo; // $ExpectType string
// this does not include stuff from later extend args
this.bee; // $ExpectError
}
}, {
foo: 99,
bee: 'honey',
func2() {
// this includes stuff from CoreObject
this.init; // $ExpectType () => void
// this includes stuff from this extend-arg
// TODO: switch to "$ExpectType number" in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
this.foo; // $ExpectType string & number
// this includes stuff from earlier extend-args
this.bar; // $ExpectType number
// this does not include stuff from later extend args
this.money; // $ExpectError
}
}, {
foo: '99',
money: 'in the banana stand',
func3() {
// this includes stuff from CoreObject
this.init; // $ExpectType () => void
// this includes stuff from this extend-arg
this.money; // $ExpectType string
// this includes stuff from earlier extend-args
this.bee; // $ExpectType string
this.bar; // $ExpectType number
// this does not include stuff from later extend args
this.neighborhood; // $ExpectError
}
}, {
foo: '99',
neighborhood: 'sudden valley',
func4() {
// this includes stuff from CoreObject
this.init; // $ExpectType () => void
// this includes stuff from this extend-arg
this.neighborhood; // $ExpectType string
// this includes stuff from earlier extend-args
this.bee; // $ExpectType string
this.bar; // $ExpectType number
this.money; // $ExpectType string
}
}).create();
// TODO: enable in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
// assertType<number>(co8.foo); // $ExpectError
assertType<number>(co8.bar); // $ExpectType number
assertType<string>(co8.money); // $ExpectType string
assertType<() => Array<string | number>>(co8.baz); // $ExpectType () => (string | number)[]
+53
View File
@@ -0,0 +1,53 @@
import Ember from 'ember';
const da = Ember.DataAdapter.create();
const filters = da.getFilters();
filters.includes({ name: 'foo', desc: 'bar'}); // $ExpectType boolean
filters.includes({}); // $ExpectError
filters[0].name; // $ExpectType string
filters[0].desc; // $ExpectType string
da.watchModelTypes(// $ExpectType () => void
function added(wrappedTypes) {
wrappedTypes;
wrappedTypes[0].release; // $ExpectType () => void
wrappedTypes[0].type.columns[0].desc; // $ExpectType string
wrappedTypes[0].type.columns[0].name; // $ExpectType string
wrappedTypes[0].type.count; // $ExpectType number
wrappedTypes[0].type.name; // $ExpectType string
},
function updated(wrappedTypes) {
wrappedTypes;
wrappedTypes[0].release; // $ExpectType () => void
wrappedTypes[0].type.columns[0].desc; // $ExpectType string
wrappedTypes[0].type.columns[0].name; // $ExpectType string
wrappedTypes[0].type.count; // $ExpectType number
wrappedTypes[0].type.name; // $ExpectType string
}
);
da.watchModelTypes(() => void); // $ExpectError
da.watchRecords('house', // $ExpectType () => void
function added(records) {
records[0].object; // $ExpectType object
records[0].columnValues; // $ExpectType object
},
function updated(records) {
records[0].object; // $ExpectType object
records[0].columnValues; // $ExpectType object
},
function removed(idx, count) {
idx; // $ExpectType number
count; // $ExpectType number
}
);
da.watchRecords(() => void); // $ExpectError
da.acceptsModelName; // $ExpectType boolean
da.containerDebugAdapter; // $ExpectType ContainerDebugAdapter
const ca: Ember.ContainerDebugAdapter = da.containerDebugAdapter;
ca.canCatalogEntriesByType('controller'); // $ExpectType boolean
ca.catalogEntriesByType('controller'); // $ExpectType string[]
+53
View File
@@ -0,0 +1,53 @@
import Ember from 'ember';
const {
runInDebug,
warn,
debug,
assert,
Debug: { registerDeprecationHandler, registerWarnHandler }
} = Ember;
/**
* @ember/debug tests
*/
runInDebug(); // $ExpectError
let x = runInDebug(() => console.log('Should not show up in prod')); // $ExpectType void
// Log a warning if we have more than 3 tomsters
const tomsterCount = 2;
warn('Too many tomsters!'); // $ExpectType void
warn('Too many tomsters!', tomsterCount <= 3); // $ExpectType void
warn('Too many tomsters!', tomsterCount <= 3, { // $ExpectType void
id: 'ember-debug.too-many-tomsters'
});
debug(); // $ExpectError
debug('Too many tomsters!'); // $ExpectType void
debug('Too many tomsters!', 'foo'); // $ExpectError
// Test for truthiness
const str = 'hello';
assert('Must pass a string', typeof str === 'string'); // $ExpectType void
// Fail unconditionally
assert('This code path should never be run'); // $ExpectType void
// next is not called, so no warnings get the default behavior
registerWarnHandler(); // $ExpectError
registerWarnHandler(() => {}); // $ExpectType void
registerWarnHandler((message, { id }, next) => { // $ExpectType void
message; // $ExpectType string
id; // $ExpectType string
next; // $ExpectType () => void
});
// next is not called, so no warnings get the default behavior
registerDeprecationHandler(); // $ExpectError
registerDeprecationHandler(() => {}); // $ExpectType void
registerDeprecationHandler((message, { id, until }, next) => { // $ExpectType void
message; // $ExpectType string
id; // $ExpectType string
until; // $ExpectType string
next; // $ExpectType () => void
});
+1 -1
View File
@@ -2,4 +2,4 @@
// Disable tslint here b/c the generic is used to let us do a type coercion and
// validate that coercion works for the type value "passed into" the function.
// tslint:disable-next-line:no-unnecessary-generics
export declare function assertType<T>(value: T): void;
export declare function assertType<T>(value: T): T;
@@ -0,0 +1,82 @@
import { Ember } from "ember";
import { computed } from "@ember/object";
import { UnwrapComputedPropertySetters, UnwrapComputedPropertyGetters, UnwrapComputedPropertySetter, UnwrapComputedPropertyGetter } from "ember/-private-types/object/computed";
import ComputedProperty from "@ember/object/computed";
import { assertType } from "../lib/assert";
class Example1 extends Ember.Object.extend({
firstName: '',
lastName: '',
allNames: computed('fullName', function() {
return [this.fullName];
}),
fullName: computed('firstName', 'lastName', function() {
return `${this.firstName} ${this.lastName}`;
})
}) {
allNames!: ComputedProperty<string[]>;
fullName!: ComputedProperty<string>;
}
let unwrappedGetters1: UnwrapComputedPropertyGetters<Example1> = {} as any;
unwrappedGetters1.firstName; // $ExpectType string
unwrappedGetters1.lastName; // $ExpectType string
unwrappedGetters1.fullName; // $ExpectType string
unwrappedGetters1.allNames; // $ExpectType string[]
let unwrappedSetters1: UnwrapComputedPropertySetters<Example1> = {} as any;
unwrappedSetters1.firstName; // $ExpectType string
unwrappedSetters1.lastName; // $ExpectType string
unwrappedSetters1.fullName; // $ExpectType string
unwrappedSetters1.allNames; // $ExpectType string[]
class Example2 extends Ember.Object.extend({
allNames: computed('fullName', function() {
return [this.fullName + ''];
}) ,
fullName: computed('firstName', 'lastName', function() {
return `${this.firstName} ${this.lastName}`;
})
}) {
firstName = '';
lastName = '';
foo() {
this.fullName; // $ExpectType ComputedProperty<string, string>
this.allNames; // $ExpectType ComputedProperty<string[], string[]>
this.firstName; // $ExpectType string
this.lastName; // $ExpectType string
this.get('fullName').split(','); // $ExpectType string[]
this.get('allNames')[0]; // $ExpectType string
this.get('firstName').split(','); // $ExpectType string[]
this.get('lastName').split(','); // $ExpectType string[]
}
}
let ex2 = new Example2();
let unwrappedGetters2: UnwrapComputedPropertyGetters<typeof ex2> = (ex2 as any) as UnwrapComputedPropertyGetters<typeof ex2>;
assertType<string>(unwrappedGetters2.firstName); // $ExpectType string
assertType<string>(unwrappedGetters2.lastName); // $ExpectType string
assertType<string>(unwrappedGetters2.fullName); // $ExpectType string
assertType<string[]>(unwrappedGetters2.allNames); // $ExpectType string[]
let unwrappedSetters2: UnwrapComputedPropertySetters<typeof ex2> = null as any;
assertType<string>(unwrappedSetters2.firstName); // $ExpectType string
assertType<string>(unwrappedSetters2.lastName); // $ExpectType string
assertType<string>(unwrappedSetters2.fullName); // $ExpectType string
assertType<string[]>(unwrappedSetters2.allNames); // $ExpectType string[]
ex2.fullName; // $ExpectType ComputedProperty<string, string>
ex2.allNames; // $ExpectType ComputedProperty<string[], string[]>
ex2.firstName; // $ExpectType string
type UnwStringSet = UnwrapComputedPropertySetter<string>; // $ExpectType string
type UnwStringGet = UnwrapComputedPropertyGetter<string>; // $ExpectType string
type UnwCpStringSet1 = UnwrapComputedPropertySetter<ComputedProperty<string>>; // $ExpectType string
type UnwCpStringGet1 = UnwrapComputedPropertyGetter<ComputedProperty<string>>; // $ExpectType string
type UnwCpStringSet2 = UnwrapComputedPropertySetter<ComputedProperty<string, string>>; // $ExpectType string
type UnwCpStringGet2 = UnwrapComputedPropertyGetter<ComputedProperty<string, string>>; // $ExpectType string
type UnwCpStringSet3 = UnwrapComputedPropertySetter<ComputedProperty<number, string>>; // $ExpectType string
type UnwCpStringGet3 = UnwrapComputedPropertyGetter<ComputedProperty<number, string>>; // $ExpectType number
type UnwCpStringSet4 = UnwrapComputedPropertySetter<ComputedProperty<string, number>>; // $ExpectType number
type UnwCpStringGet4 = UnwrapComputedPropertyGetter<ComputedProperty<string, number>>; // $ExpectType string
@@ -0,0 +1,175 @@
import Observable from "@ember/object/observable";
import { UnwrapComputedPropertyGetter, UnwrapComputedPropertyGetters, UnwrapComputedPropertySetters, UnwrapComputedPropertySetter } from "ember/-private-types/object/computed";
// tslint-disable-next-line
import { assertType } from "../lib/assert";
import { Ember } from "ember";
import { ExtractPropertyNamesOfType } from "ember/-private-types/utils";
class OtherThing {
observerOfDemo(target: DemoObservable, key: 'foo') {}
}
class DemoObservable implements Observable {
foo: string;
isFoo = true;
bar: [boolean, boolean];
baz?: number;
constructor() {
this.foo = 'hello';
this.bar = [false, true];
this.baz = 9;
this.addObserver('foo', this, 'fooDidChange');
this.addObserver('foo', this, 'fooDidChangeProtected'); // $ExpectError
this.addObserver('foo', this, this.fooDidChange);
this.addObserver('foo', this, this.fooDidChangeProtected);
const ot = new OtherThing();
this.addObserver('foo', ot, ot.observerOfDemo);
Ember.addObserver(this, 'foo', this, 'fooDidChange');
Ember.addObserver(this, 'foo', this, 'fooDidChangeProtected'); // $ExpectError
Ember.addObserver(this, 'foo', this, this.fooDidChange);
Ember.addObserver(this, 'foo', this, this.fooDidChangeProtected);
this.removeObserver('foo', this, 'fooDidChange');
this.removeObserver('foo', this, 'fooDidChangeProtected'); // $ExpectError
this.removeObserver('foo', this, this.fooDidChange);
this.removeObserver('foo', this, this.fooDidChangeProtected);
Ember.removeObserver(this, 'foo', this, 'fooDidChange');
Ember.removeObserver(this, 'foo', this, 'fooDidChangeProtected'); // $ExpectError
Ember.removeObserver(this, 'foo', this, this.fooDidChange);
const lambda = () => {
this.fooDidChange(this, 'foo');
};
this.addObserver('foo', lambda);
this.addObserver('foo', (sender, key, value, rev) => {
assertType<DemoObservable>(sender);
assertType<'foo'>(key);
assertType<string>(value);
assertType<number>(rev);
});
this.removeObserver('foo', lambda);
Ember.addObserver(this, 'foo', lambda);
Ember.removeObserver(this, 'foo', lambda);
}
fooDidChange(obj: this, propName: 'foo') {}
protected fooDidChangeProtected(obj: this, propName: 'foo') {}
get<K extends keyof this>(key: K): UnwrapComputedPropertyGetter<this[K]> {
throw new Error("Method not implemented.");
}
getProperties<K extends keyof this>(list: K[]): Pick<UnwrapComputedPropertyGetters<this>, K>;
getProperties<K extends keyof this>(...list: K[]): Pick<UnwrapComputedPropertyGetters<this>, K>;
getProperties(...rest: any[]): any {
throw new Error("Method not implemented.");
}
set<K extends keyof this>(key: K, value: this[K]): this[K] {
throw new Error("Method not implemented.");
}
setProperties<K extends keyof this>(hash: Pick<this, K>): Pick< UnwrapComputedPropertySetters<this>, K> {
throw new Error("Method not implemented.");
}
notifyPropertyChange(keyName: string): this {
throw new Error("Method not implemented.");
}
addObserver<Target>(key: keyof this, target: Target, method: keyof Target | ((this: Target, sender: this, key: string, value: any, rev: number) => void)): void;
addObserver<K extends keyof this>(key: K, method: keyof this | ((this: this, sender: this, key: K, value: this[K], rev: number) => void)): void;
addObserver(key: any, target: any, method?: any) {
throw new Error("Method not implemented.");
}
removeObserver<Target>(key: keyof this, target: Target, method: keyof Target | ((this: Target, sender: this, key: string, value: any, rev: number) => void)): void;
removeObserver(key: keyof this, method: keyof this | ((this: this, sender: this, key: string, value: any, rev: number) => void)): void;
removeObserver(key: any, target: any, method?: any): void {
throw new Error("Method not implemented.");
}
getWithDefault<K extends keyof this>(key: K, defaultValue: UnwrapComputedPropertyGetter<this[K]>): UnwrapComputedPropertyGetter<this[K]> {
throw new Error("Method not implemented.");
}
incrementProperty(keyName: ExtractPropertyNamesOfType<this, number | undefined>, increment?: number): number {
throw new Error("Method not implemented.");
}
decrementProperty(keyName: ExtractPropertyNamesOfType<this, number | undefined>, decrement?: number): number {
throw new Error("Method not implemented.");
}
toggleProperty(keyName: ExtractPropertyNamesOfType<this, boolean | undefined>): boolean {
throw new Error("Method not implemented.");
}
cacheFor<K extends keyof this>(key: K): UnwrapComputedPropertyGetter<this[K]> | undefined {
throw new Error("Method not implemented.");
}
}
const o = new DemoObservable();
/**
* get
*/
assertType<string>(o.get('foo')); // $ExpectType string
assertType<[boolean, boolean]>(o.get('bar')); // $ExpectType [boolean, boolean]
assertType<number | undefined>(o.get('baz')); // $ExpectType number | undefined
/**
* incrementProperty, decrementProperty
*/
assertType<number>(o.incrementProperty('baz')); // $ExpectType number
assertType<number>(o.decrementProperty('baz')); // $ExpectType number
assertType<number>(o.incrementProperty('baz', 3)); // $ExpectType number
assertType<number>(o.decrementProperty('baz', 12)); // $ExpectType number
// non-numeric property case
assertType<number>(o.incrementProperty('bar')); // $ExpectError
assertType<number>(o.decrementProperty('bar')); // $ExpectError
// empty case
assertType<number>(o.incrementProperty()); // $ExpectError
assertType<number>(o.decrementProperty()); // $ExpectError
/**
* toggleProperty
*/
o.toggleProperty('isFoo'); // $ExpectType boolean
o.toggleProperty(); // $ExpectError
/**
* getWithDefault
*/
assertType<string>(o.getWithDefault('foo', 'zzz')); // $ExpectType string
assertType<[boolean, boolean]>(o.getWithDefault('bar', [false, false])); // $ExpectType [boolean, boolean]
assertType<number | undefined>(o.getWithDefault('baz', 10)); // $ExpectType number | undefined
// improper arguments cases
assertType<number | undefined>(o.getWithDefault('baz', '10')); // $ExpectError
assertType<number | undefined>(o.getWithDefault('baz')); // $ExpectError
assertType<number | undefined>(o.getWithDefault()); // $ExpectError
/**
* getProperties
*/
// ('foo', 'bar')
assertType<{ foo: string, bar: [boolean, boolean] }>(o.getProperties('foo', 'bar')); // $ExpectType { foo: string; bar: [boolean, boolean]; }
// ['foo', 'bar']
assertType<{ foo: string, bar: [boolean, boolean] }>(o.getProperties(['foo', 'bar'])); // $ExpectType { foo: string; bar: [boolean, boolean]; }
// empty cases
assertType<{}>(o.getProperties()); // $ExpectType {}
assertType<{}>(o.getProperties([])); // $ExpectType {}
// property that doesn't exist
assertType<any>(o.getProperties('jeanShorts', 'foo')); // $ExpectError
assertType<any>(o.getProperties(['foo', 'jeanShorts'])); // $ExpectError
/**
* set
*/
assertType<string>(o.set('foo', 'abc')); // $ExpectType string
assertType<[boolean, boolean]>(o.set('bar', [false, false])); // $ExpectType [boolean, boolean]
assertType<number | undefined>(o.set('baz', undefined)); // $ExpectType number | undefined
assertType<number | undefined>(o.set('baz', 10)); // $ExpectType number | undefined
// property that doesn't exist
assertType<any>(o.set('jeanShorts', 10)); // $ExpectError
/**
* setProperties
*/
assertType<{ foo: string, bar: [boolean, boolean] }>(o.setProperties({ foo: 'abc', bar: [true, true] })); // $ExpectType { foo: string; bar: [boolean, boolean]; }
// empty case
assertType<{}>(o.setProperties({})); // $ExpectType {}
// property that doesn't exist
assertType<any>(o.setProperties({ jeanShorts: 'under the pants' })); // $ExpectError
/**
* notifyPropertyChange
*/
assertType<DemoObservable>(o.notifyPropertyChange('foo')); // $ExpectType DemoObservable
assertType<Observable>(o.notifyPropertyChange('jeanShorts')); // $ExpectError
@@ -0,0 +1,62 @@
/**
* These tests validate that the method of pulling property types off of this
* continues to work. We use this technique in the critical Observable interface
* that serves to implement a lot of Ember.CoreObject's functionality
*/
class BoxedProperty<Get, Set = Get> {
__getType: Get;
__setType: Set;
}
type UnboxGetProperty<T> = T extends BoxedProperty<infer V, any> ? V : T;
type UnboxSetProperty<T> = T extends BoxedProperty<any, infer V> ? V : T;
class GetAndSet {
get<K extends keyof this>(key: K): UnboxGetProperty<this[K]> {
return this[key] as any;
}
set<K extends keyof this>(key: K, newVal: UnboxSetProperty<this[K]>): UnboxSetProperty<this[K]> {
const rawVal: UnboxSetProperty<this[K]> = this[key] as any;
if (rawVal instanceof BoxedProperty) {
rawVal.__setType = newVal;
}
this[key] = newVal as any;
return newVal;
}
}
class Foo123 extends GetAndSet {
// tslint:disable-next-line:no-inferrable-types
a: number;
b: [boolean, boolean];
c: string;
cpA!: BoxedProperty<string>;
constructor() {
super();
this.a = 1;
this.b = [true, false];
this.c = 'hello';
}
}
let f = new Foo123();
f.get('a'); // $ExpectType number
f.set('a'); // $ExpectError
f.set('a', '1'); // $ExpectError
f.set('a', 1); // $ExpectType number
f.get('b'); // $ExpectType [boolean, boolean]
f.set('b', 1); // $ExpectError
f.set('b', []); // $ExpectError
f.set('b', [true]); // $ExpectError
f.set('b', [false, true]); // $ExpectType [boolean, boolean]
f.set('b', [false, true, false]); // $ExpectError
f.get('c'); // $ExpectType string
f.set('c', '1'); // $ExpectType string
f.get('cpA'); // $ExpectType string
f.set('cpA', ['newValue']); // $ExpectError
f.set('cpA', 'newValue'); // $ExpectType string
+49 -2
View File
@@ -3,8 +3,8 @@ import * as utils from '@ember/utils';
import { assertType } from "./lib/assert";
function testTypeOf() {
utils.typeOf(); // $ExpectType string
utils.typeOf({}); // $ExpectType string
utils.typeOf(); // $ExpectType "undefined"
const str: string = utils.typeOf({});
}
function testIsNoneType() {
@@ -127,3 +127,50 @@ function testTryInvoke() {
// Reversed arg types
Ember.tryInvoke(new Foo(), 'add', ['4', 3]); // $ExpectType undefined
}
(function() {
/** typeOf */
// TODO: more specific return type in @types/ember https://github.com/typed-ember/ember-cli-typescript/issues/259
Ember.typeOf(); // $ExpectType "undefined"
Ember.typeOf(null); // $ExpectType "null"
Ember.typeOf(undefined); // $ExpectType "undefined"
Ember.typeOf('michael'); // $ExpectType "string"
// tslint:disable-next-line:no-construct
Ember.typeOf(new String('michael')); // $ExpectType "string"
Ember.typeOf(101); // $ExpectType "number"
// tslint:disable-next-line:no-construct
Ember.typeOf(new Number(101)); // $ExpectType "number"
Ember.typeOf(true); // $ExpectType "boolean"
// tslint:disable-next-line:no-construct
Ember.typeOf(new Boolean(true)); // $ExpectType "boolean"
Ember.typeOf(() => 4); // $ExpectType "function"
Ember.typeOf([1, 2, 90]); // $ExpectType "array"
Ember.typeOf(/abc/); // $ExpectType "regexp"
Ember.typeOf(new Date()); // $ExpectType "date"
Ember.typeOf(({} as any) as FileList); // $ExpectType "filelist"
Ember.typeOf(Ember.Object.extend()); // $ExpectType "class"
Ember.typeOf(Ember.Object.create()); // $ExpectType "instance"
Ember.typeOf(new Error('teamocil')); // $ExpectType "error"
Ember.typeOf((new Date()) as RegExp | Date); // "regexp" | "date"
})();
(function() { /* assign */
Ember.assign({}, { a: 'b'});
Ember.assign({}, { a: 'b'}).a; // $ExpectType string
Ember.assign({ a: 6 }, { a: 'b'}).a; // $ExpectType string
Ember.assign({ a: 6 }, {}).a; // $ExpectType number
Ember.assign({ b: 6 }, {}).a; // $ExpectError
Ember.assign({}, { b: 6 }, {}).b; // $ExpectType number
Ember.assign({ a: 'hello' }, { b: 6 }, {}).a; // $ExpectType string
Ember.assign({ a: 'hello' }, { b: 6 }, { a: true }).a; // $ExpectType boolean
Ember.assign({ a: 'hello' }, '', { a: true }).a; // $ExpectError
Ember.assign({ d: ['gobias industries'] }, { a: 'hello' }, { b: 6 }, { a: true }).d; // $ExpectType string[]
}());
(function() { /* merge */
Ember.merge({}, { a: 'b'});
Ember.merge({}, { a: 'b'}).a; // $ExpectType string
Ember.merge({ a: 6 }, { a: 'b'}).a; // $ExpectType string
Ember.merge({ a: 6 }, {}).a; // $ExpectType number
Ember.merge({ b: 6 }, {}).a; // $ExpectError
}());
+11 -2
View File
@@ -20,7 +20,14 @@
},
"files": [
"index.d.ts",
"-private-types/utils.d.ts",
"-private-types/mixin.d.ts",
"-private-types/object.d.ts",
"-private-types/object/computed.d.ts",
"test/lib/assert.ts",
"test/private/computed-tests.ts",
"test/private/observable-tests.ts",
"test/techniques/properties-from-this.ts",
"test/access-modifier.ts",
"test/application-instance.ts",
"test/application.ts",
@@ -30,9 +37,11 @@
"test/component.ts",
"test/computed.ts",
"test/controller.ts",
"test/core-object.ts",
"test/create-negative.ts",
"test/create.ts",
"test/create.ts",
"test/data-adapter.ts",
"test/debug.ts",
"test/detect-instance.ts",
"test/detect.ts",
"test/ember-tests.ts",
@@ -51,8 +60,8 @@
"test/route.ts",
"test/router.ts",
"test/run.ts",
"test/string.ts",
"test/string-ext.ts",
"test/string.ts",
"test/test.ts",
"test/transition.ts",
"test/utils.ts",
+4
View File
@@ -0,0 +1,4 @@
import Ember from 'ember';
export const deprecate: typeof Ember.deprecate;
export const deprecateFunc: typeof Ember.deprecateFunc;
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class GlobalsResolver extends Ember.DefaultResolver { }
+13
View File
@@ -0,0 +1,13 @@
// Type definitions for @ember/application 3.0
// Project: http://emberjs.com/
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import Ember from 'ember';
export default class Application extends Ember.Application { }
export const getOwner: typeof Ember.getOwner;
export const onLoad: typeof Ember.onLoad;
export const runLoadHooks: typeof Ember.runLoadHooks;
export const setOwner: typeof Ember.setOwner;
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class ApplicationInstance extends Ember.ApplicationInstance { }
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class Resolver extends Ember.Resolver { }
@@ -0,0 +1,29 @@
import ApplicationInstance from '@ember/application/instance';
import hbs from 'htmlbars-inline-precompile';
const appInstance = ApplicationInstance.create();
appInstance.register('some:injection', class Foo {});
appInstance.register('some:injection', class Foo {}, {
singleton: true,
});
appInstance.register('some:injection', class Foo {}, {
instantiate: false,
});
appInstance.register('templates:foo/bar', hbs`<h1>Hello World</h1>`);
appInstance.register('some:injection', class Foo {}, {
singleton: false,
instantiate: true,
});
appInstance.factoryFor('router:main');
appInstance.lookup('route:basic');
appInstance.boot();
(async () => {
await appInstance.boot();
})();
+41
View File
@@ -0,0 +1,41 @@
import Application from "@ember/application";
import EmberObject from "@ember/object";
const BaseApp = Application.extend({
modulePrefix: 'my-app'
});
BaseApp.initializer({
name: 'my-initializer',
initialize(app) {
app.register('foo:bar', EmberObject.extend({ foo: 'bar' }));
}
});
BaseApp.instanceInitializer({
name: 'my-instance-initializer',
initialize(app) {
app.lookup('foo:bar').get('foo');
}
});
const App1 = BaseApp.create({
rootElement: '#app-one',
customEvents: {
paste: 'paste'
}
});
const App2 = BaseApp.create({
rootElement: '#app-two',
customEvents: {
mouseenter: null,
mouseleave: null
}
});
const App3 = BaseApp.create();
const App3Instance1 = App3.buildInstance(); // $ExpectType ApplicationInstance
const App3Instance2 = App3.buildInstance({ foo: 'bar' }); // $ExpectType ApplicationInstance
@@ -0,0 +1,14 @@
import { deprecate, deprecateFunc } from '@ember/application/deprecations';
deprecate('this is no longer advised', false, {
id: 'no-longer-advised',
until: 'v4.0'
});
deprecate('this is no longer advised', false);
deprecateFunc('this is no longer advised', () => {});
deprecateFunc(
'this is no longer advised',
{ id: 'no-longer-do-this', until: 'v4.0' },
() => {}
);
@@ -0,0 +1,6 @@
import GlobalsResolver from "@ember/application/globals-resolver";
const gr = GlobalsResolver.create();
gr.resolve('App.IndexController');
gr.resolve(); // $ExpectError
@@ -0,0 +1,3 @@
import Resolver from "@ember/application/resolver";
const res = Resolver.create();
+37
View File
@@ -0,0 +1,37 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@ember/application": ["ember__application"],
"@ember/application/*": ["ember__application/*"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"deprecations.d.ts",
"globals-resolver.d.ts",
"index.d.ts",
"instance.d.ts",
"resolver.d.ts",
"test/application.ts",
"test/deprecations.ts",
"test/resolver.ts",
"test/globals-resolver.ts",
"test/application-instance.ts"
]
}
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "dtslint/dt.json",
"rules": {}
}
+13
View File
@@ -0,0 +1,13 @@
// Type definitions for @ember/array 3.0
// Project: http://emberjs.com/
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import Ember from 'ember';
type EmberArray<T> = Ember.Array<T>;
export const EmberArray: typeof Ember.Array;
export default EmberArray;
export const A: typeof Ember.A;
export const isArray: typeof Ember.isArray;
+5
View File
@@ -0,0 +1,5 @@
import Ember from 'ember';
type MutableArray<T> = Ember.MutableArray<T>;
export const MutableArray: typeof Ember.MutableArray;
export default MutableArray;
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class ArrayProxy<T> extends Ember.ArrayProxy<T> { }
+22
View File
@@ -0,0 +1,22 @@
import { assertType } from './lib/assert';
import EmberObject from '@ember/object';
import { ArrayPrototypeExtensions } from '@ember/array/types/prototype-extensions';
declare global {
interface Array<T> extends ArrayPrototypeExtensions<T> {}
}
class Person extends EmberObject {
name: string;
}
const person = Person.create({ name: 'Joe' });
const array = [person];
assertType<number>(array.get('length'));
assertType<Person | undefined>(array.get('firstObject'));
assertType<string[]>(array.mapBy('name'));
assertType<string[]>(array.map(p => p.get('name')));
assertType<Person[]>(array.sortBy('name'));
assertType<Person[]>(array.uniq());
assertType<Person[]>(array.uniqBy('name'));
+27
View File
@@ -0,0 +1,27 @@
import { assertType } from './lib/assert';
import ArrayProxy from '@ember/array/proxy';
import { A } from '@ember/array';
const pets = ['dog', 'cat', 'fish'];
const proxy = ArrayProxy.create({ content: A(pets) });
proxy.get('firstObject'); // 'dog'
proxy.set('content', A(['amoeba', 'paramecium']));
proxy.get('firstObject'); // 'amoeba'
const overridden = ArrayProxy.create({
content: A(pets),
objectAtContent(idx: number): string {
return this.get('content').objectAt(idx)!.toUpperCase();
}
});
overridden.get('firstObject'); // 'DOG'
class MyNewProxy<T> extends ArrayProxy<T> {
isNew = true;
}
const x = MyNewProxy.create({ content: A([1, 2, 3]) }) as MyNewProxy<number>;
assertType<number | undefined>(x.get('firstObject'));
assertType<boolean>(x.isNew);
+56
View File
@@ -0,0 +1,56 @@
import { assertType } from './lib/assert';
import EmberObject from '@ember/object';
import EmberArray, { A } from '@ember/array';
import MutableArray from '@ember/array/mutable';
type Person = typeof Person.prototype;
const Person = EmberObject.extend({
name: '',
isHappy: false
});
const people = A([
Person.create({ name: 'Yehuda', isHappy: true }),
Person.create({ name: 'Majd', isHappy: false }),
]);
assertType<number>(people.get('length'));
assertType<Person>(people.get('lastObject'));
assertType<Person>(people.get('firstObject'));
assertType<boolean>(people.isAny('isHappy'));
assertType<boolean>(people.isAny('isHappy', 'false'));
const persons1: Person[] = people.filterBy('isHappy');
const persons2: MutableArray<Person> = people.filterBy('isHappy');
const persons3: Person[] = people.rejectBy('isHappy');
const persons4: MutableArray<Person> = people.rejectBy('isHappy');
const persons5: Person[] = people.filter((person) => person.get('name') === 'Yehuda');
const persons6: MutableArray<Person> = people.filter((person) => person.get('name') === 'Yehuda');
assertType<typeof people>(people.get('[]'));
assertType<Person>(people.get('[]').get('firstObject')); // $ExpectType any
assertType<EmberArray<boolean>>(people.mapBy('isHappy')); // $ExpectType Array<boolean>
assertType<any[]>(people.mapBy('name.length'));
const last = people.get('lastObject'); // $ExpectType ({ name: string; isHappy: boolean; } & EmberObject & { name: string; isHappy: boolean; }) | undefined
if (last) {
assertType<string>(last.get('name'));
}
const first = people.get('lastObject');
if (first) {
assertType<boolean>(first.get('isHappy'));
}
const letters: EmberArray<string> = A(['a', 'b', 'c']);
const codes: number[] = letters.map((item, index, enumerable) => {
assertType<string>(item);
assertType<number>(index);
return item.charCodeAt(0);
});
const value = '1,2,3';
const filters = A(value.split(','));
filters.push('4');
filters.sort();
+5
View File
@@ -0,0 +1,5 @@
/** Static assertion that `value` has type `T` */
// Disable tslint here b/c the generic is used to let us do a type coercion and
// validate that coercion works for the type value "passed into" the function.
// tslint:disable-next-line:no-unnecessary-generics
export declare function assertType<T>(value: T): T;
+35
View File
@@ -0,0 +1,35 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@ember/array": ["ember__array"],
"@ember/array/*": ["ember__array/*"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"mutable.d.ts",
"proxy.d.ts",
"types/prototype-extensions.d.ts",
"test/lib/assert.ts",
"test/array.ts",
"test/array-ext.ts",
"test/array-proxy.ts"
]
}
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "dtslint/dt.json",
"rules": {}
}
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export interface ArrayPrototypeExtensions<T> extends Ember.MutableArray<T>, Ember.Observable, Ember.Copyable {}
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class Checkbox extends Ember.Checkbox { }
+17
View File
@@ -0,0 +1,17 @@
import Ember from 'ember';
export default class Helper extends Ember.Helper { }
/**
* In many cases, the ceremony of a full `Helper` class is not required.
* The `helper` method create pure-function helpers without instances. For
* example:
* ```app/helpers/format-currency.js
* import { helper } from '@ember/component/helper';
* export default helper(function(params, hash) {
* let cents = params[0];
* let currency = hash.currency;
* return `${currency}${cents * 0.01}`;
* });
* ```
*/
export function helper(helperFn: (params: any[], hash?: any) => any): any;
+9
View File
@@ -0,0 +1,9 @@
// Type definitions for @ember/component 3.0
// Project: http://emberjs.com/
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import Ember from 'ember';
export default class Component extends Ember.Component { }
+123
View File
@@ -0,0 +1,123 @@
import Component from '@ember/component';
import Object, { computed, get } from '@ember/object';
import hbs from 'htmlbars-inline-precompile';
import { assertType } from "./lib/assert";
Component.extend({
layout: hbs`
<div>
{{yield}}
</div>
`,
});
Component.extend({
layout: 'my-layout',
});
const MyComponent = Component.extend();
assertType<string | string[]>(get(MyComponent, 'positionalParams'));
const component1 = Component.extend({
actions: {
hello(name: string) {
console.log('Hello', name);
},
},
});
Component.extend({
name: '',
hello(name: string) {
this.set('name', name);
},
});
Component.extend({
tagName: 'em',
});
Component.extend({
classNames: ['my-class', 'my-other-class'],
});
Component.extend({
classNameBindings: ['propertyA', 'propertyB'],
propertyA: 'from-a',
propertyB: computed(function() {
if (!this.get('propertyA')) {
return 'from-b';
}
}),
});
Component.extend({
classNameBindings: ['hovered'],
hovered: true,
});
Component.extend({
classNameBindings: ['messages.empty'],
messages: Object.create({
empty: true,
}),
});
Component.extend({
classNameBindings: ['isEnabled:enabled:disabled'],
isEnabled: true,
});
Component.extend({
classNameBindings: ['isEnabled::disabled'],
isEnabled: true,
});
Component.extend({
tagName: 'a',
attributeBindings: ['href'],
href: 'http://google.com',
});
Component.extend({
tagName: 'a',
attributeBindings: ['url:href'],
url: 'http://google.com',
});
Component.extend({
tagName: 'use',
attributeBindings: ['xlinkHref:xlink:href'],
xlinkHref: '#triangle',
});
Component.extend({
tagName: 'input',
attributeBindings: ['disabled'],
disabled: false,
});
Component.extend({
tagName: 'input',
attributeBindings: ['disabled'],
disabled: computed(() => {
if ('someLogic') {
return true;
} else {
return false;
}
}),
});
Component.extend({
tagName: 'form',
attributeBindings: ['novalidate'],
novalidate: null,
});
Component.extend({
click(event: object) {
// will be called when an instance's
// rendered element is clicked
},
});
+25
View File
@@ -0,0 +1,25 @@
import { assertType } from './lib/assert';
import Helper, { helper } from '@ember/component/helper';
class Timestamp extends Helper {
timer?: ReturnType<typeof setInterval>;
now = new Date();
init() {
super.init();
this.timer = setInterval(() => {
this.set('now', new Date());
this.recompute();
}, 100);
}
willDestroy() {
clearInterval(this.timer);
}
}
const addHelper = helper(function add([a, b]: number[]) {
return a + b;
});
const dasherizeHelper = helper(function dasherize([str]: string[], { delim = '-'}) {
return str.split(/[\s\n\_\.]+/g).join(delim);
});
+5
View File
@@ -0,0 +1,5 @@
/** Static assertion that `value` has type `T` */
// Disable tslint here b/c the generic is used to let us do a type coercion and
// validate that coercion works for the type value "passed into" the function.
// tslint:disable-next-line:no-unnecessary-generics
export declare function assertType<T>(value: T): T;
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class TextArea extends Ember.TextArea { }
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class TextField extends Ember.TextField { }
+35
View File
@@ -0,0 +1,35 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@ember/component": ["ember__component"],
"@ember/component/*": ["ember__component/*"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"checkbox.d.ts",
"text-area.d.ts",
"text-field.d.ts",
"helper.d.ts",
"test/lib/assert.ts",
"test/component.ts",
"test/helper.ts"
]
}
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "dtslint/dt.json",
"rules": {}
}
@@ -0,0 +1,11 @@
import Controller from '@ember/controller';
Controller.extend ({
queryParams: ['category'],
category: null,
isExpanded: false,
toggleBody() {
this.toggleProperty('isExpanded');
}
});
+15
View File
@@ -0,0 +1,15 @@
// Type definitions for @ember/controller 3.0
// Project: http://emberjs.com/
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import Ember from 'ember';
export default class Controller extends Ember.Controller { }
export const inject: typeof Ember.inject.controller;
// A type registry for Ember `Controller`s. Meant to be declaration-merged
// so string lookups resolve to the correct type.
// tslint:disable-next-line no-empty-interface
export interface Registry {}
+28
View File
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@ember/controller": ["ember__controller"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ember__controller-tests.ts"
]
}
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "dtslint/dt.json",
"rules": {}
}
+2
View File
@@ -0,0 +1,2 @@
import Ember from 'ember';
export default class ContainerDebugAdapter extends Ember.ContainerDebugAdapter { }
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class DataAdapter extends Ember.DataAdapter {}
+45
View File
@@ -0,0 +1,45 @@
import { runInDebug, warn, debug, assert, registerWarnHandler, registerDeprecationHandler } from "@ember/debug";
/**
* @ember/debug tests
*/
runInDebug(); // $ExpectError
runInDebug(() => console.log('Should not show up in prod')); // $ExpectType void
// Log a warning if we have more than 3 tomsters
const tomsterCount = 2;
warn('Too many tomsters!'); // $ExpectType void
warn('Too many tomsters!', tomsterCount <= 3); // $ExpectType void
warn('Too many tomsters!', tomsterCount <= 3, { // $ExpectType void
id: 'ember-debug.too-many-tomsters'
});
debug(); // $ExpectError
debug('Too many tomsters!'); // $ExpectType void
debug('Too many tomsters!', 'foo'); // $ExpectError
// Test for truthiness
const str = 'hello';
assert('Must pass a string', typeof str === 'string'); // $ExpectType void
// Fail unconditionally
assert('This code path should never be run'); // $ExpectType void
// next is not called, so no warnings get the default behavior
registerWarnHandler(); // $ExpectError
registerWarnHandler(() => {}); // $ExpectType void
registerWarnHandler((message, { id }, next) => { // $ExpectType void
message; // $ExpectType string
id; // $ExpectType string
next; // $ExpectType () => void
});
// next is not called, so no warnings get the default behavior
registerDeprecationHandler(); // $ExpectError
registerDeprecationHandler(() => {}); // $ExpectType void
registerDeprecationHandler((message, { id, until }, next) => { // $ExpectType void
message; // $ExpectType string
id; // $ExpectType string
until; // $ExpectType string
next; // $ExpectType () => void
});
+14
View File
@@ -0,0 +1,14 @@
// Type definitions for @ember/debug 3.0
// Project: http://emberjs.com/
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import Ember from 'ember';
export const assert: typeof Ember.assert;
export const debug: typeof Ember.debug;
export const inspect: typeof Ember.inspect;
export const registerDeprecationHandler: typeof Ember.Debug.registerDeprecationHandler;
export const registerWarnHandler: typeof Ember.Debug.registerWarnHandler;
export const runInDebug: typeof Ember.runInDebug;
export const warn: typeof Ember.warn;
+31
View File
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@ember/debug": ["ember__debug"],
"@ember/debug/*": ["ember__debug/*"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"data-adapter.d.ts",
"container-debug-adapter.d.ts",
"ember__debug-tests.ts"
]
}
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "dtslint/dt.json",
"rules": { }
}
+10
View File
@@ -0,0 +1,10 @@
// Type definitions for @ember/engine 3.0
// Project: http://emberjs.com/
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import Ember from 'ember';
export default class Engine extends Ember.Engine { }
export const getEngineParent: typeof Ember.getEngineParent;
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class EngineInstance extends Ember.EngineInstance { }
@@ -0,0 +1,26 @@
import EngineInstance from '@ember/engine/instance';
const engineInstance = EngineInstance.create();
engineInstance.register('some:injection', class Foo {});
engineInstance.register('some:injection', class Foo {}, {
singleton: true,
});
engineInstance.register('some:injection', class Foo {}, {
instantiate: false,
});
engineInstance.register('some:injection', class Foo {}, {
singleton: false,
instantiate: true,
});
engineInstance.factoryFor('router:main');
engineInstance.lookup('route:basic');
engineInstance.boot();
(async () => {
await engineInstance.boot();
})();
+41
View File
@@ -0,0 +1,41 @@
import Engine from "@ember/engine";
import EmberObject from "@ember/object";
const BaseEngine = Engine.extend({
modulePrefix: 'my-engine'
});
BaseEngine.initializer({
name: 'my-initializer',
initialize(engine) {
engine.register('foo:bar', EmberObject.extend({ foo: 'bar' }));
}
});
BaseEngine.instanceInitializer({
name: 'my-instance-initializer',
initialize(engine) {
engine.lookup('foo:bar').get('foo');
}
});
const Engine1 = BaseEngine.create({
rootElement: '#engine-one',
customEvents: {
paste: 'paste'
}
});
const Engine2 = BaseEngine.create({
rootElement: '#engine-two',
customEvents: {
mouseenter: null,
mouseleave: null
}
});
const Engine3 = BaseEngine.create();
const Engine3Instance1 = Engine3.buildInstance();
const Engine3Instance2 = Engine3.buildInstance({ foo: 'bar' });
+31
View File
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@ember/engine": ["ember__engine"],
"@ember/engine/*": ["ember__engine/*"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"instance.d.ts",
"test/engine.ts",
"test/engine-instance.ts"
]
}
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "dtslint/dt.json",
"rules": {}
}
+3
View File
@@ -0,0 +1,3 @@
import Error from '@ember/error';
new Error('Fuuuuuuuu'); // $ExpectType Error
+10
View File
@@ -0,0 +1,10 @@
// Type definitions for @ember/error 3.0
// Project: http://emberjs.com/
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import Ember from 'ember';
declare const Error: typeof Ember.Error;
export default Error;
+28
View File
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@ember/error": ["ember__error"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ember__error-tests.ts"
]
}
+5
View File
@@ -0,0 +1,5 @@
{
"extends": "dtslint/dt.json",
"rules": {
}
}
@@ -0,0 +1,25 @@
import { assign, merge } from '@ember/polyfills';
(() => { /* assign */
assign({}, { a: 'b'});
assign({}, { a: 'b'}).a; // $ExpectType string
assign({ a: 6 }, { a: 'b'}).a; // $ExpectType string
assign({ a: 6 }, {}).a; // $ExpectType number
assign({ b: 6 }, {}).a; // $ExpectError
// TODO enable after https://github.com/typed-ember/ember-cli-typescript/issues/291
// assign({}, { b: 6 }, {}).b; // $ExpectType number
assign({ a: 'hello' }, { b: 6 }, {}).a; // $ExpectType string
// TODO enable after https://github.com/typed-ember/ember-cli-typescript/issues/291
// assign({ a: 'hello' }, { b: 6 }, { a: true }).a; // $ExpectType boolean
// TODO enable after https://github.com/typed-ember/ember-cli-typescript/issues/291
// assign({ a: 'hello' }, '', { a: true }).a; // $ExpectError
assign({ d: ['gobias industries'] }, { a: 'hello' }, { b: 6 }, { a: true }).d; // $ExpectType string[]
})();
(() => { /* merge */
merge({}, { a: 'b'});
merge({}, { a: 'b'}).a; // $ExpectType string
merge({ a: 6 }, { a: 'b'}).a; // $ExpectType string
merge({ a: 6 }, {}).a; // $ExpectType number
merge({ b: 6 }, {}).a; // $ExpectError
})();
+10
View File
@@ -0,0 +1,10 @@
// Type definitions for @ember/polyfills 3.0
// Project: http://emberjs.com/
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import Ember from 'ember';
export const assign: typeof Ember.assign;
export const merge: typeof Ember.merge;
+28
View File
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@ember/polyfills": ["ember__polyfills"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ember__polyfills-tests.ts"
]
}
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "dtslint/dt.json",
"rules": {}
}
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class AutoLocation extends Ember.AutoLocation { }
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class HashLocation extends Ember.HashLocation { }
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class HistoryLocation extends Ember.HistoryLocation { }
+8
View File
@@ -0,0 +1,8 @@
// Type definitions for @ember/routing 3.0
// Project: http://emberjs.com/
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
export { default as Route } from '@ember/routing/route';
export { default as Router } from '@ember/routing/router';
+3
View File
@@ -0,0 +1,3 @@
import Ember from 'ember';
export default class LinkComponent extends Ember.LinkComponent { }
+4
View File
@@ -0,0 +1,4 @@
import Ember from 'ember';
export const Location: typeof Ember.Location;
export default Location;

Some files were not shown because too many files have changed in this diff Show More