diff --git a/types/ember/index.d.ts b/types/ember/index.d.ts index 3ff82919dc..cee4ebc780 100755 --- a/types/ember/index.d.ts +++ b/types/ember/index.d.ts @@ -324,6 +324,17 @@ declare module 'ember' { interface ArrayPrototypeExtensions extends MutableArray, Observable, Copyable {} + interface StringPrototypeExtensions { + camelize(): string; + decamelize(): string; + classify(): string; + capitalize(): string; + loc(values?: string[]): string; + dasherize(): string; + underscore(): string; + w(): string[]; + } + /** * Given a fullName return a factory manager. */ @@ -2453,7 +2464,7 @@ declare module 'ember' { function fmt(...args: string[]): string; function htmlSafe(str: string): Handlebars.SafeString; function isHTMLSafe(str: string): boolean; - function loc(...args: string[]): string; + function loc(template: string, args?: string[]): string; function underscore(str: string): string; function w(str: string): string[]; } diff --git a/types/ember/test/string-ext.ts b/types/ember/test/string-ext.ts new file mode 100644 index 0000000000..e4ac77d5b4 --- /dev/null +++ b/types/ember/test/string-ext.ts @@ -0,0 +1,28 @@ +import Ember from 'ember'; + +declare global { + interface String extends Ember.StringPrototypeExtensions {} +} + +''.dasherize('foo'); // $ExpectError +''.dasherize(); // $ExpectType string + +''.camelize(); // $ExpectType string +''.camelize('blue man group'); // $ExpectError + +''.decamelize(); // $ExpectType string +''.decamelize('blue man group'); // $ExpectError + +''.underscore(); // $ExpectType string +''.underscore('blue man group'); // $ExpectError + +''.w(); // $ExpectType string[] + +''.classify(); // $ExpectType string +''.classify('blue man group'); // $ExpectError + +''.capitalize(); // $ExpectType string +''.capitalize('blue man group'); // $ExpectError + +''.loc(); // $ExpectType string +''.loc("_Hello World"); // $ExpectError diff --git a/types/ember/test/string.ts b/types/ember/test/string.ts new file mode 100644 index 0000000000..0543bd60d0 --- /dev/null +++ b/types/ember/test/string.ts @@ -0,0 +1,36 @@ +import Ember from 'ember'; + +const { dasherize, camelize, capitalize, classify, decamelize, htmlSafe, loc, underscore, w } = Ember.String; + +dasherize(); // $ExpectError +dasherize('blue man group'); // $ExpectType string +dasherize('', ''); // $ExpectError + +camelize(); // $ExpectError +camelize('blue man group'); // $ExpectType string +camelize('', ''); // $ExpectError + +decamelize(); // $ExpectError +decamelize('blue man group'); // $ExpectType string +decamelize('', ''); // $ExpectError + +underscore(); // $ExpectError +underscore('blue man group'); // $ExpectType string +underscore('', ''); // $ExpectError + +w(); // $ExpectError +w('blue man group'); // $ExpectType string[] +w('', ''); // $ExpectError + +classify(); // $ExpectError +classify('blue man group'); // $ExpectType string +classify('', ''); // $ExpectError + +capitalize(); // $ExpectError +capitalize('blue man group'); // $ExpectType string +capitalize('', ''); // $ExpectError + +loc(); // $ExpectError +loc("_Hello World"); // $ExpectType string +// TODO - fix this case upstream in @types/ember https://github.com/typed-ember/ember-cli-typescript/issues/281 +loc("_Hello %@ %@", ["John", "Smith"]); // $ExpectType string diff --git a/types/ember/tsconfig.json b/types/ember/tsconfig.json index 29f20bcc44..74ec227219 100755 --- a/types/ember/tsconfig.json +++ b/types/ember/tsconfig.json @@ -21,39 +21,41 @@ "files": [ "index.d.ts", "test/lib/assert.ts", - "test/application.ts", "test/access-modifier.ts", "test/application-instance.ts", - "test/engine.ts", - "test/engine-instance.ts", + "test/application.ts", + "test/array-ext.ts", + "test/array-proxy.ts", + "test/array.ts", + "test/component.ts", + "test/computed.ts", + "test/controller.ts", + "test/create-negative.ts", + "test/create.ts", + "test/create.ts", + "test/detect-instance.ts", + "test/detect.ts", "test/ember-tests.ts", + "test/engine-instance.ts", + "test/engine.ts", "test/error.ts", "test/event.ts", "test/extend.ts", - "test/create.ts", - "test/create-negative.ts", - "test/create.ts", + "test/function-ext.ts", + "test/helper.ts", + "test/inject.ts", + "test/mixin.ts", "test/object.ts", "test/observable.ts", - "test/mixin.ts", "test/reopen.ts", - "test/detect.ts", - "test/detect-instance.ts", - "test/array.ts", - "test/array-ext.ts", - "test/array-proxy.ts", - "test/helper.ts", - "test/computed.ts", - "test/component.ts", - "test/function-ext.ts", - "test/inject.ts", - "test/utils.ts", - "test/transition.ts", + "test/route.ts", "test/router.ts", "test/run.ts", + "test/string.ts", + "test/string-ext.ts", "test/test.ts", - "test/controller.ts", - "test/route.ts", + "test/transition.ts", + "test/utils.ts", "test/view-utils.ts" ] }