mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-24 11:29:30 +08:00
In TypeScript 0.8.1.1, a 'declare' is needed in front of the 'class Spinner', since without it the compiler attempts to compile it as an actual class definition, and fails with:
Message: Overload declaration lacks definition
Line number: 27
Column number: 5
Source error:
Line 26: class Spinner {
Line 27: constructor (options?: SpinnerOptions);
-------------^
Line 28: spin(target?: any);
The test in the typescript codebase that confirms this is intentional behavior is in tests/compiler/class.ts
http://typescript.codeplex.com/SourceControl/changeset/view/2bee84410e02#tests/compiler/class.ts
****
describe('Testing function signatures inside classes', function () {
it('Regression test - was previously giving runtime error', function () {
var code = "class A { a(completed: () => any): void; }";
Harness.Compiler.compileString(code, 'fnsig-inside-classes', function (result) {
assert.compilerWarning(result, 1, 10, 'Overload declaration lacks definition');
assert.equal(result.errors.length, 1);
});
});
});
****
The compiler code that implements the check is in src/compiler/signatures.ts
http://typescript.codeplex.com/SourceControl/changeset/view/2bee84410e02#src/compiler/signatures.ts
****
if (!hasConstruct && !this.definitionSignature && this.signatures[i].declAST && this.signatures[i].declAST.isOverload && !hasFlag(this.signatures[i].declAST.fncFlags, FncFlags.Ambient)) {
checker.errorReporter.simpleError(this.signatures[i].declAST, "Overload declaration lacks definition");
}
****
By adding the 'declare', we tell the TypeScript compiler that this is just intending to expose the API of the class, not the actual implementation.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
// Type definitions for Spin.js 1.2
|
|
// Project: http://fgnass.github.com/spin.js/
|
|
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
|
|
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
|
|
|
|
|
interface SpinnerOptions {
|
|
lines?: number; // The number of lines to draw
|
|
length?: number; // The length of each line
|
|
width?: number; // The line thickness
|
|
radius?: number; // The radius of the inner circle
|
|
corners?: number; // Corner roundness (0..1)
|
|
rotate?: number; // The rotation offset
|
|
color?: string; // #rgb or #rrggbb
|
|
speed?: number; // Rounds per second
|
|
trail?: number; // Afterglow percentage
|
|
shadow?: bool; // Whether to render a shadow
|
|
hwaccel?: bool; // Whether to use hardware acceleration
|
|
className?: string; // The CSS class to assign to the spinner
|
|
zIndex?: number; // The z-index (defaults to 2000000000)
|
|
top?: string; // Top position relative to parent in px
|
|
left?: string; // Left position relative to parent in px
|
|
}
|
|
|
|
|
|
declare class Spinner {
|
|
constructor (options?: SpinnerOptions);
|
|
spin(target?: any);
|
|
stop();
|
|
lines(el, o);
|
|
opacity(el, i, val);
|
|
}
|